EnTT 4.0.0
Loading...
Searching...
No Matches
enum.hpp
1#ifndef ENTT_CORE_ENUM_HPP
2#define ENTT_CORE_ENUM_HPP
3
4#include "../stl/concepts.hpp"
5#include "../stl/type_traits.hpp"
6
7namespace entt {
8
13template<typename Type>
14struct enum_as_bitmask: stl::false_type {};
15
17template<typename Type>
18requires requires {
19 requires stl::is_enum_v<Type>;
20 { Type::_entt_enum_as_bitmask } -> stl::same_as<Type>;
21}
22struct enum_as_bitmask<Type>: stl::true_type {};
23
28template<typename Type>
30
35template<typename Type>
36// check again that it is an enum to deal with incorrect specializations
37concept enum_bitmask = stl::is_enum_v<Type> && enum_as_bitmask_v<Type>;
38
39} // namespace entt
40
49template<entt::enum_bitmask Type>
50[[nodiscard]] constexpr Type operator|(const Type lhs, const Type rhs) noexcept {
51 return static_cast<Type>(static_cast<entt::stl::underlying_type_t<Type>>(lhs) | static_cast<entt::stl::underlying_type_t<Type>>(rhs));
52}
53
55template<entt::enum_bitmask Type>
56[[nodiscard]] constexpr Type operator&(const Type lhs, const Type rhs) noexcept {
57 return static_cast<Type>(static_cast<entt::stl::underlying_type_t<Type>>(lhs) & static_cast<entt::stl::underlying_type_t<Type>>(rhs));
58}
59
61template<entt::enum_bitmask Type>
62[[nodiscard]] constexpr Type operator^(const Type lhs, const Type rhs) noexcept {
63 return static_cast<Type>(static_cast<entt::stl::underlying_type_t<Type>>(lhs) ^ static_cast<entt::stl::underlying_type_t<Type>>(rhs));
64}
65
73template<entt::enum_bitmask Type>
74[[nodiscard]] constexpr Type operator~(const Type value) noexcept {
75 return static_cast<Type>(~static_cast<entt::stl::underlying_type_t<Type>>(value));
76}
77
79template<entt::enum_bitmask Type>
80[[nodiscard]] constexpr bool operator!(const Type value) noexcept {
81 return !static_cast<entt::stl::underlying_type_t<Type>>(value);
82}
83
85template<entt::enum_bitmask Type>
86constexpr Type &operator|=(Type &lhs, const Type rhs) noexcept {
87 return (lhs = (lhs | rhs));
88}
89
91template<entt::enum_bitmask Type>
92constexpr Type &operator&=(Type &lhs, const Type rhs) noexcept {
93 return (lhs = (lhs & rhs));
94}
95
97template<entt::enum_bitmask Type>
98constexpr Type &operator^=(Type &lhs, const Type rhs) noexcept {
99 return (lhs = (lhs ^ rhs));
100}
101
102#endif
Specifies that an enum class supports bitmask operations.
Definition enum.hpp:37
EnTT default namespace.
Definition dense_map.hpp:25
constexpr bool enum_as_bitmask_v
Helper variable template.
Definition enum.hpp:29
Enable bitmask support for enum classes.
Definition enum.hpp:14