EnTT: src/entt/core/enum.hpp Source File

EnTT 3.16.0

Loading...
Searching...
No Matches
enum.hpp
1#ifndef ENTT_CORE_ENUM_HPP
2#define ENTT_CORE_ENUM_HPP
3
4#include <type_traits>
5
6namespace entt {
7
12template<typename Type, typename = void>
13 struct enum_as_bitmask: std::false_type {};
14
16template<typename Type>
17 struct enum_as_bitmask<Type, std::void_t<decltype(Type::_entt_enum_as_bitmask)>>: std::is_enum<Type> {};
18
23template<typename Type>
24 inline constexpr bool enum_as_bitmask_v = enum_as_bitmask<Type>::value;
25
26} // namespace entt
27
36template<typename Type>
37[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
38operator|(const Type lhs, const Type rhs) noexcept {
39 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) | static_cast<std::underlying_type_t<Type>>(rhs));
40}
41
43template<typename Type>
44[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
45operator&(const Type lhs, const Type rhs) noexcept {
46 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) & static_cast<std::underlying_type_t<Type>>(rhs));
47}
48
50template<typename Type>
51[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
52operator^(const Type lhs, const Type rhs) noexcept {
53 return static_cast<Type>(static_cast<std::underlying_type_t<Type>>(lhs) ^ static_cast<std::underlying_type_t<Type>>(rhs));
54}
55
63template<typename Type>
64[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type>
65operator~(const Type value) noexcept {
66 return static_cast<Type>(~static_cast<std::underlying_type_t<Type>>(value));
67}
68
70template<typename Type>
71[[nodiscard]] constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, bool>
72operator!(const Type value) noexcept {
73 return !static_cast<std::underlying_type_t<Type>>(value);
74}
75
77template<typename Type>
78constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
79operator|=(Type &lhs, const Type rhs) noexcept {
80 return (lhs = (lhs | rhs));
81}
82
84template<typename Type>
85constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
86operator&=(Type &lhs, const Type rhs) noexcept {
87 return (lhs = (lhs & rhs));
88}
89
91template<typename Type>
92constexpr std::enable_if_t<entt::enum_as_bitmask_v<Type>, Type &>
93operator^=(Type &lhs, const Type rhs) noexcept {
94 return (lhs = (lhs ^ rhs));
95}
96
97#endif
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::enum_as_bitmask_v
constexpr bool enum_as_bitmask_v
Helper variable template.
Definition enum.hpp:24
entt::enum_as_bitmask
Enable bitmask support for enum classes.
Definition enum.hpp:13