SimpleWindow
载入中...
搜索中...
未找到
EnumBit.h
1#pragma once
2
3#include <type_traits>
4
5#define _SW_ENUM_ENABLE_BIT_OPERATIONS(T) \
6 template <> \
7 struct _EnumSupportBitOperations<T> : std::true_type { \
8 }
9
10namespace sw
11{
15 template <typename T>
16 struct _EnumSupportBitOperations : std::false_type {
17 };
18
22 template <typename T>
23 inline constexpr auto operator|(T a, T b)
24 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
25 {
26 using TUnderlying = typename std::underlying_type<T>::type;
27 return static_cast<T>(static_cast<TUnderlying>(a) | static_cast<TUnderlying>(b));
28 }
29
33 template <typename T>
34 inline constexpr auto operator|=(T &a, T b)
35 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
36 {
37 return a = a | b;
38 }
39
43 template <typename T>
44 inline constexpr auto operator&(T a, T b)
45 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
46 {
47 using TUnderlying = typename std::underlying_type<T>::type;
48 return static_cast<T>(static_cast<TUnderlying>(a) & static_cast<TUnderlying>(b));
49 }
50
54 template <typename T>
55 inline constexpr auto operator&=(T &a, T b)
56 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
57 {
58 return a = a & b;
59 }
60
64 template <typename T>
65 inline constexpr auto operator^(T a, T b)
66 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
67 {
68 using TUnderlying = typename std::underlying_type<T>::type;
69 return static_cast<T>(static_cast<TUnderlying>(a) ^ static_cast<TUnderlying>(b));
70 }
71
75 template <typename T>
76 inline constexpr auto operator^=(T &a, T b)
77 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T &>::type
78 {
79 return a = a ^ b;
80 }
81
85 template <typename T>
86 inline constexpr auto operator~(T a)
87 -> typename std::enable_if<std::is_enum<T>::value && _EnumSupportBitOperations<T>::value, T>::type
88 {
89 using TUnderlying = typename std::underlying_type<T>::type;
90 return static_cast<T>(~static_cast<TUnderlying>(a));
91 }
92}
值转换器接口
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:34
constexpr auto operator~(T a) -> typename std::enable_if< std::is_enum< T >::value &&_EnumSupportBitOperations< T >::value, T >::type
为标记_EnumSupportBitOperations的枚举类型提供按位取反运算
Definition EnumBit.h:86
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:55
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:44
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:65
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:23
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:76
用于标记枚举是否支持位运算
Definition EnumBit.h:16