Use constexpr for evaluating bitwise enums

This commit is contained in:
Jack Andersen 2016-07-31 10:25:40 -10:00
parent c4db28821e
commit cf3dfcddff
1 changed files with 5 additions and 5 deletions

View File

@ -77,29 +77,29 @@ typedef struct stat64 stat64_t;
#ifndef ENABLE_BITWISE_ENUM #ifndef ENABLE_BITWISE_ENUM
#define ENABLE_BITWISE_ENUM(type)\ #define ENABLE_BITWISE_ENUM(type)\
inline type operator|(type a, type b)\ constexpr type operator|(type a, type b)\
{\ {\
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, type b)\ constexpr type operator&(type a, type b)\
{\ {\
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, const type& b)\
{\ {\
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, const type& b)\
{\ {\
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~(const type& key)\ constexpr type operator~(const type& key)\
{\ {\
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));\