1 #ifndef ENTT_CORE_ENUM_HPP
2 #define ENTT_CORE_ENUM_HPP
5 #include "../config/config.h"
13 template<
typename Type,
typename =
void>
17 template<
typename Type>
18 struct enum_as_bitmask<Type, std::void_t<decltype(Type::_entt_enum_as_bitmask)>>: std::is_enum<Type> {};
24 template<
typename Type>
37 template<
typename Type>
38 [[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
39 operator|(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
40 return static_cast<Type
>(
static_cast<std::underlying_type_t<Type>
>(lhs) |
static_cast<std::underlying_type_t<Type>
>(rhs));
44 template<
typename Type>
45 [[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
46 operator&(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
47 return static_cast<Type
>(
static_cast<std::underlying_type_t<Type>
>(lhs) &
static_cast<std::underlying_type_t<Type>
>(rhs));
51 template<
typename Type>
52 [[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
53 operator^(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
54 return static_cast<Type
>(
static_cast<std::underlying_type_t<Type>
>(lhs) ^
static_cast<std::underlying_type_t<Type>
>(rhs));
64 template<
typename Type>
65 [[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
66 operator~(
const Type value) ENTT_NOEXCEPT {
67 return static_cast<Type
>(~static_cast<std::underlying_type_t<Type>>(value));
71 template<
typename Type>
72 [[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>,
bool>
73 operator!(
const Type value) ENTT_NOEXCEPT {
74 return !
static_cast<std::underlying_type_t<Type>
>(value);
78 template<
typename Type>
79 constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
80 operator|=(Type &lhs,
const Type rhs) ENTT_NOEXCEPT {
81 return (lhs = (lhs | rhs));
85 template<
typename Type>
86 constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
87 operator&=(Type &lhs,
const Type rhs) ENTT_NOEXCEPT {
88 return (lhs = (lhs & rhs));
92 template<
typename Type>
93 constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
94 operator^=(Type &lhs,
const Type rhs) ENTT_NOEXCEPT {
95 return (lhs = (lhs ^ rhs));
constexpr bool enum_as_bitmask_v
Helper variable template.
Enable bitmask support for enum classes.