cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::traits::enum_wrapper< EnumType > Class Template Reference

类型安全的枚举包装器/Type-safe enum wrapper More...

#include <type_traits.hpp>

Public Types

using underlying_type = typename std::underlying_type< EnumType >::type
 

Public Member Functions

constexpr enum_wrapper (EnumType value)
 
constexpr operator EnumType () const
 
constexpr auto to_underlying () const -> underlying_type
 

Detailed Description

template<typename EnumType>
class toolbox::traits::enum_wrapper< EnumType >

类型安全的枚举包装器/Type-safe enum wrapper

Template Parameters
EnumType要包装的枚举类型/Enum type to wrap
enum class Color { Red, Green, Blue };
// 创建和使用包装器/Create and use wrapper
enum_wrapper<Color> color(Color::Red);
Color raw_color = color; // 隐式转换/Implicit conversion
auto value = color.to_underlying(); // 获取底层值/Get underlying value
// 编译期检查/Compile-time check
// enum_wrapper<int> error; // 编译错误:不是枚举类型/Compilation error: not
an enum type
类型安全的枚举包装器/Type-safe enum wrapper
Definition type_traits.hpp:473

Member Typedef Documentation

◆ underlying_type

template<typename EnumType >
using toolbox::traits::enum_wrapper< EnumType >::underlying_type = typename std::underlying_type<EnumType>::type

Constructor & Destructor Documentation

◆ enum_wrapper()

template<typename EnumType >
constexpr toolbox::traits::enum_wrapper< EnumType >::enum_wrapper ( EnumType  value)
inlineconstexpr

Member Function Documentation

◆ operator EnumType()

template<typename EnumType >
constexpr toolbox::traits::enum_wrapper< EnumType >::operator EnumType ( ) const
inlineconstexpr

◆ to_underlying()

template<typename EnumType >
constexpr auto toolbox::traits::enum_wrapper< EnumType >::to_underlying ( ) const -> underlying_type
inlineconstexpr

The documentation for this class was generated from the following file: