EnTT  3.10.0
enum.hpp
1 #ifndef ENTT_CORE_ENUM_HPP
2 #define ENTT_CORE_ENUM_HPP
3 
4 #include <type_traits>
5 #include "../config/config.h"
6 
7 namespace entt {
8 
13 template<typename Type, typename = void>
14 struct enum_as_bitmask: std::false_type {};
15 
17 template<typename Type>
18 struct enum_as_bitmask<Type, std::void_t<decltype(Type::_entt_enum_as_bitmask)>>: std::is_enum<Type> {};
19 
24 template<typename Type>
26 
27 } // namespace entt
28 
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));
41 }
42 
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));
48 }
49 
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));
55 }
56 
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));
68 }
69 
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);
75 }
76 
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));
82 }
83 
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));
89 }
90 
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));
96 }
97 
98 #endif
EnTT default namespace.
Definition: dense_map.hpp:22
constexpr bool enum_as_bitmask_v
Helper variable template.
Definition: enum.hpp:25
Enable bitmask support for enum classes.
Definition: enum.hpp:14