1 #ifndef ENTT_CORE_FLAG_HPP
2 #define ENTT_CORE_FLAG_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::true_type {};
24 template<
typename Type>
37 template<
typename Type>
38 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
39 operator|(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
40 return 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<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
46 operator&(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
47 return 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<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
53 operator^(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
54 return 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<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
66 operator~(
const Type value) ENTT_NOEXCEPT {
67 return Type{~static_cast<std::underlying_type_t<Type>>(value)};
71 template<
typename Type>
72 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && 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<std::is_enum_v<Type> && 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<std::is_enum_v<Type> && 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<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type &>
94 operator^=(Type &lhs,
const Type rhs) ENTT_NOEXCEPT {
95 return (lhs = (lhs ^ rhs));
99 template<
typename Type>
100 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
101 operator==(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
102 return (
static_cast<std::underlying_type_t<Type>
>(lhs) ==
static_cast<std::underlying_type_t<Type>
>(rhs));
106 template<
typename Type>
107 [[nodiscard]] constexpr std::enable_if_t<std::is_enum_v<Type> && entt::enum_as_bitmask_v<Type>, Type>
108 operator!=(
const Type lhs,
const Type rhs) ENTT_NOEXCEPT {
109 return !(lhs == rhs);
constexpr bool enum_as_bitmask_v
Helper variable template.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
Enable bitmask support for enum classes.