SimpleWindow
载入中...
搜索中...
未找到
EnumBit.h
1#pragma once
2
3#include <type_traits>
4
10#define _SW_ENUM_ENABLE_BIT_OPERATIONS(T) \
11 template <> \
12 struct _EnumSupportBitOperations<T> : std::true_type { \
13 }
14
15namespace sw
16{
22 template <typename T>
23 struct _EnumSupportBitOperations : std::false_type {
24 };
25
33 template <typename T>
34 constexpr auto operator|(T a, T b)
35 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
36 {
37 using TUnderlying = typename std::underlying_type<T>::type;
38 return static_cast<T>(static_cast<TUnderlying>(a) | static_cast<TUnderlying>(b));
39 }
40
48 template <typename T>
49 constexpr auto operator|=(T &a, T b)
50 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
51 {
52 return a = a | b;
53 }
54
62 template <typename T>
63 constexpr auto operator&(T a, T b)
64 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
65 {
66 using TUnderlying = typename std::underlying_type<T>::type;
67 return static_cast<T>(static_cast<TUnderlying>(a) & static_cast<TUnderlying>(b));
68 }
69
77 template <typename T>
78 constexpr auto operator&=(T &a, T b)
79 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
80 {
81 return a = a & b;
82 }
83
91 template <typename T>
92 constexpr auto operator^(T a, T b)
93 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
94 {
95 using TUnderlying = typename std::underlying_type<T>::type;
96 return static_cast<T>(static_cast<TUnderlying>(a) ^ static_cast<TUnderlying>(b));
97 }
98
106 template <typename T>
107 constexpr auto operator^=(T &a, T b)
108 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
109 {
110 return a = a ^ b;
111 }
112
119 template <typename T>
120 constexpr auto operator~(T a)
121 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
122 {
123 using TUnderlying = typename std::underlying_type<T>::type;
124 return static_cast<T>(~static_cast<TUnderlying>(a));
125 }
126}
值转换器接口
Definition IValueConverter.h:14
SimpleWindow框架的顶级命名空间,所有公共类型、控件、枚举和工具函数均定义于此。
Definition Alignment.h:4
constexpr auto operator|=(T &a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T & >::type
为标记_EnumSupportBitOperations的枚举类型提供按位或赋值运算
Definition EnumBit.h:49
constexpr auto operator~(T a) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T >::type
为标记_EnumSupportBitOperations的枚举类型提供按位取反运算
Definition EnumBit.h:120
constexpr auto operator&=(T &a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T & >::type
为标记_EnumSupportBitOperations的枚举类型提供按位与赋值运算
Definition EnumBit.h:78
constexpr auto operator&(T a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T >::type
为标记_EnumSupportBitOperations的枚举类型提供按位与运算
Definition EnumBit.h:63
constexpr auto operator^(T a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T >::type
为标记_EnumSupportBitOperations的枚举类型提供按位异或运算
Definition EnumBit.h:92
constexpr auto operator|(T a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T >::type
为标记_EnumSupportBitOperations的枚举类型提供按位或运算
Definition EnumBit.h:34
constexpr auto operator^=(T &a, T b) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T & >::type
为标记_EnumSupportBitOperations的枚举类型提供按位异或赋值运算
Definition EnumBit.h:107
用于标记枚举是否支持位运算
Definition EnumBit.h:23