enum_name
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
mgutility Namespace Reference

Checks for MSVC compiler version. More...

Classes

struct  bad_optional_access
 Exception thrown when accessing an empty optional. More...
 
class  basic_string_view
 A basic string view class template. More...
 
struct  custom_enum
 Provides the custom names map for an enumeration type. More...
 
struct  custom_enum< Position >
 
class  enum_for_each
 A class template for iterating over enum values. More...
 
struct  enum_range
 Provides the range for an enumeration type. More...
 
struct  enum_range< color >
 
struct  enum_range< Position >
 
struct  nullopt_t
 Represents a null optional. More...
 
class  optional
 A class template that provides optional (nullable) objects. More...
 
struct  pair
 

Typedefs

template<typename T >
using flat_map = pair<T, const char *>[]
 
using string_view = basic_string_view<char>
 

Functions

template<typename Enum >
constexpr auto enum_to_underlying (Enum e) noexcept -> detail::underlying_type_t< Enum >
 Converts an enum value to its underlying integer value.
 
template<int Min, int Max, typename Enum >
MGUTILITY_CNSTXPR auto enum_name (Enum e) noexcept -> detail::string_or_view_t< Enum >
 Gets the name of an enum value.
 
template<typename Enum , int Min = enum_range<Enum>::min, int Max = enum_range<Enum>::max, detail::enable_if_t<!detail::has_bit_or< Enum >::value, bool > = true>
MGUTILITY_CNSTXPR auto to_enum (mgutility::string_view str) noexcept -> mgutility::optional< Enum >
 Converts a string to an enum value.
 
template<typename Enum , int Min = enum_range<Enum>::min, int Max = enum_range<Enum>::max>
MGUTILITY_CNSTXPR auto enum_cast (int value) noexcept -> mgutility::optional< Enum >
 Casts an integer value to an enum value.
 

Variables

auto nullopt = nullopt_t{}
 A global instance of nullopt_t to represent null optional.
 

Detailed Description

Checks for MSVC compiler version.

If the MSVC version is less than 2017, an error is raised.

Defines the MGUTILITY_CPLUSPLUS macro for MSVC and other compilers.

For MSVC, it uses _MSVC_LANG. For other compilers, it uses __cplusplus.

Function Documentation

◆ enum_cast()

template<typename Enum , int Min = enum_range<Enum>::min, int Max = enum_range<Enum>::max>
MGUTILITY_CNSTXPR auto mgutility::enum_cast ( int value) -> mgutility::optional<Enum>
noexcept

Casts an integer value to an enum value.

Template Parameters
EnumThe enum type.
MinThe minimum enum value, default is enum_range<Enum>::min.
MaxThe maximum enum value, default is enum_range<Enum>::max.
Parameters
valueThe integer value to cast.
Returns
An optional enum value.

◆ enum_name()

template<int Min, int Max, typename Enum >
MGUTILITY_CNSTXPR auto mgutility::enum_name ( Enum e) -> detail::string_or_view_t<Enum>
noexcept

Gets the name of an enum value.

Template Parameters
MinThe minimum enum value.
MaxThe maximum enum value.
EnumThe enum type.
Parameters
eThe enum value.
Returns
A string view or string representing the name of the enum value.
Template Parameters
EnumThe enum type.
MinThe minimum enum value, default is enum_range<Enum>::min.
MaxThe maximum enum value, default is enum_range<Enum>::max.
Parameters
eThe enum value.
Returns
A string view or string representing the name of the enum value.

◆ enum_to_underlying()

template<typename Enum >
constexpr auto mgutility::enum_to_underlying ( Enum e) -> detail::underlying_type_t<Enum>
constexprnoexcept

Converts an enum value to its underlying integer value.

Template Parameters
EnumThe enum type.
Parameters
eThe enum value.
Returns
The underlying integer value of the enum.

◆ to_enum()

template<typename Enum , int Min = enum_range<Enum>::min, int Max = enum_range<Enum>::max, detail::enable_if_t<!detail::has_bit_or< Enum >::value, bool > = true>
MGUTILITY_CNSTXPR auto mgutility::to_enum ( mgutility::string_view str) -> mgutility::optional<Enum>
noexcept

Converts a string to an enum value.

Converts a string to an enum bitmask value.

Template Parameters
EnumThe enum type.
MinThe minimum enum value, default is enum_range<Enum>::min.
MaxThe maximum enum value, default is enum_range<Enum>::max.
Parameters
strThe string view representing the enum name.
Returns
An optional enum value.
Template Parameters
EnumThe enum type.
MinThe minimum enum value, default is enum_range<Enum>::min.
MaxThe maximum enum value, default is enum_range<Enum>::max.
Parameters
strThe string view representing the enum name.
Returns
An optional enum bitmask value.