44struct IsBitmaskEnum : std::is_same<decltype(isBitmaskEnum(std::declval<T>())), std::true_type> {};
52constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator&(T lhs, T rhs)
noexcept {
53 using U =
typename std::underlying_type_t<T>;
54 return static_cast<T
>(
static_cast<U
>(lhs) &
static_cast<U
>(rhs));
59constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator|(T lhs, T rhs)
noexcept {
60 using U =
typename std::underlying_type_t<T>;
61 return static_cast<T
>(
static_cast<U
>(lhs) |
static_cast<U
>(rhs));
66constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator^(T lhs, T rhs)
noexcept {
67 using U =
typename std::underlying_type_t<T>;
68 return static_cast<T
>(
static_cast<U
>(lhs) ^
static_cast<U
>(rhs));
73constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator~(T rhs)
noexcept {
74 using U =
typename std::underlying_type_t<T>;
75 return static_cast<T
>(~static_cast<U>(rhs));
82constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator|=(T& lhs, T rhs)
noexcept {
83 using U =
typename std::underlying_type_t<T>;
84 lhs =
static_cast<T
>(
static_cast<U
>(lhs) |
static_cast<U
>(rhs));
90constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator&=(T& lhs, T rhs)
noexcept {
91 using U =
typename std::underlying_type_t<T>;
92 lhs =
static_cast<T
>(
static_cast<U
>(lhs) &
static_cast<U
>(rhs));
98constexpr typename std::enable_if_t<IsBitmaskEnum<T>::value, T>
operator^=(T& lhs, T rhs)
noexcept {
99 using U =
typename std::underlying_type_t<T>;
100 lhs =
static_cast<T
>(
static_cast<U
>(lhs) ^
static_cast<U
>(rhs));
129 static_assert(std::is_enum_v<T>);
139 : mask_(toUnderlying(
mask)) {}
146 constexpr explicit operator T() const noexcept {
147 return static_cast<T
>(mask_);
168 mask_ |= toUnderlying(
mask);
180 mask_ &= ~toUnderlying(
mask);
191 constexpr bool all() const noexcept {
197 return (mask_ & toUnderlying(
mask)) == toUnderlying(
mask);
201 constexpr bool any() const noexcept {
202 return mask_ != empty;
207 return (mask_ & toUnderlying(
mask)) != empty;
211 constexpr bool none() const noexcept {
212 return mask_ == empty;
217 return (mask_ & toUnderlying(
mask)) == empty;
230template <
typename T,
typename U>
236template <
typename T,
typename U>
242template <
typename T,
typename U>
248template <
typename T,
typename U>
Bitmask using (scoped) enums.
std::underlying_type_t< T > Underlying
constexpr bool allOf(T mask) const noexcept
Check if all of the specified bits are set.
constexpr Bitmask & reset(T mask) noexcept
Reset specified bits.
constexpr bool noneOf(T mask) const noexcept
Check if none of the specified bits are set.
constexpr bool all() const noexcept
Check if all bits are set.
constexpr Bitmask(Underlying mask) noexcept
Create a bitmask from the underlying type.
constexpr Bitmask & set(T mask) noexcept
Set specified bits.
constexpr bool any() const noexcept
Check if any bits are set.
constexpr Bitmask & reset() noexcept
Reset all bits.
constexpr Bitmask & flip() noexcept
Flip all bits.
constexpr bool none() const noexcept
Check if none bits are set.
constexpr Bitmask() noexcept=default
Create an empty bitmask.
constexpr Bitmask & set() noexcept
Set all bits.
constexpr bool anyOf(T mask) const noexcept
Check if any of the specified bits are set.
constexpr Underlying get() const noexcept
Get the bitmask as the underlying type (integer).
constexpr bool operator!=(Bitmask< T > lhs, U rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator&=(T &lhs, T rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator|(T lhs, T rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator~(T rhs) noexcept
constexpr bool operator==(U lhs, Bitmask< T > rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator|=(T &lhs, T rhs) noexcept
constexpr std::false_type isBitmaskEnum(T)
Function template to define an enum (class) as a bitmask and allow bitwise operations.
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator&(T lhs, T rhs) noexcept
constexpr bool operator!=(U lhs, Bitmask< T > rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator^(T lhs, T rhs) noexcept
constexpr std::enable_if_t< IsBitmaskEnum< T >::value, T > operator^=(T &lhs, T rhs) noexcept
constexpr bool operator==(Bitmask< T > lhs, U rhs) noexcept
Trait to define an enum (class) as a bitmask and allow bitwise operations.
Exposes the possibilities of a client to write the attributes of the node In contrast to the write mask