mirror of https://github.com/libAthena/athena.git
Merge pull request #64 from lioncash/constexpr
Global: Make operator|= and &= for enums constexpr
This commit is contained in:
commit
97ee63f0fe
|
@ -87,33 +87,33 @@ typedef struct stat64 atStat64_t;
|
||||||
|
|
||||||
#ifndef ENABLE_BITWISE_ENUM
|
#ifndef ENABLE_BITWISE_ENUM
|
||||||
#define ENABLE_BITWISE_ENUM(type) \
|
#define ENABLE_BITWISE_ENUM(type) \
|
||||||
constexpr type operator|(type a, type b) { \
|
constexpr type operator|(type a, type b) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(static_cast<T>(a) | static_cast<T>(b)); \
|
return type(static_cast<T>(a) | static_cast<T>(b)); \
|
||||||
} \
|
} \
|
||||||
constexpr type operator&(type a, type b) { \
|
constexpr type operator&(type a, type b) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(static_cast<T>(a) & static_cast<T>(b)); \
|
return type(static_cast<T>(a) & static_cast<T>(b)); \
|
||||||
} \
|
} \
|
||||||
inline type& operator|=(type& a, const type& b) { \
|
constexpr type& operator|=(type& a, type b) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
a = type(static_cast<T>(a) | static_cast<T>(b)); \
|
a = type(static_cast<T>(a) | static_cast<T>(b)); \
|
||||||
return a; \
|
return a; \
|
||||||
} \
|
} \
|
||||||
inline type& operator&=(type& a, const type& b) { \
|
constexpr type& operator&=(type& a, type b) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
a = type(static_cast<T>(a) & static_cast<T>(b)); \
|
a = type(static_cast<T>(a) & static_cast<T>(b)); \
|
||||||
return a; \
|
return a; \
|
||||||
} \
|
} \
|
||||||
constexpr type operator~(type key) { \
|
constexpr type operator~(type key) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(~static_cast<T>(key)); \
|
return type(~static_cast<T>(key)); \
|
||||||
} \
|
} \
|
||||||
constexpr bool True(type key) { \
|
constexpr bool True(type key) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
return static_cast<T>(key) != 0; \
|
return static_cast<T>(key) != 0; \
|
||||||
} \
|
} \
|
||||||
constexpr bool False(type key) { \
|
constexpr bool False(type key) noexcept { \
|
||||||
using T = std::underlying_type_t<type>; \
|
using T = std::underlying_type_t<type>; \
|
||||||
return static_cast<T>(key) == 0; \
|
return static_cast<T>(key) == 0; \
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue