You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
notcurses/include/ncpp/_flag_enum_operator_helpers.hh

53 lines
2.0 KiB
C++

#ifndef __NCPP_FLAG_ENUM_OPERATOR_HELPERS_H
#define __NCPP_FLAG_ENUM_OPERATOR_HELPERS_H
#include <type_traits>
#include "_helpers.hh"
namespace ncpp
{
#define DECLARE_ENUM_FLAG_OPERATORS(__enum_name__) \
NCPP_API_EXPORT constexpr __enum_name__ operator& (__enum_name__ x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return __enum_name__ (static_cast<etype> (x) & static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__& operator&= (__enum_name__& x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return x = __enum_name__ (static_cast<etype> (x) & static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__ operator| (__enum_name__ x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return __enum_name__ (static_cast<etype> (x) | static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__& operator|= (__enum_name__& x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return x = __enum_name__ (static_cast<etype> (x) | static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__ operator^ (__enum_name__ x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return __enum_name__ (static_cast<etype> (x) ^ static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__& operator^= (__enum_name__& x, __enum_name__ y) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return x = __enum_name__ (static_cast<etype> (x) ^ static_cast<etype> (y)); \
} \
NCPP_API_EXPORT constexpr __enum_name__& operator~ (__enum_name__& x) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return x = __enum_name__ (~static_cast<etype> (x)); \
} \
NCPP_API_EXPORT constexpr __enum_name__ operator~ (__enum_name__ x) \
{ \
typedef std::underlying_type<__enum_name__>::type etype; \
return __enum_name__ (~static_cast<etype> (x)); \
}
}
#endif