8#ifndef NUMAPP_FLAGS_HPP_
9#define NUMAPP_FLAGS_HPP_
17#define NUMAPP_ENABLE_BITFLAG(enum) \
19 struct IsFlagEnum<enum> : std::true_type { \
20 static_assert(std::is_enum_v<enum>); \
27constexpr std::underlying_type_t<Enum> ToUnderlying(Enum value)
noexcept {
28 return static_cast<std::underlying_type_t<Enum>
>(value);
31constexpr Enum FromUnderlying(std::underlying_type_t<Enum> value)
noexcept {
32 return static_cast<Enum
>(value);
73template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
74[[nodiscard]]
constexpr Enum
operator|(Enum lhs, Enum rhs)
noexcept {
75 return detail::FromUnderlying<Enum>(detail::ToUnderlying(lhs) | detail::ToUnderlying(rhs));
81template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
82constexpr Enum&
operator|=(Enum& lhs, Enum rhs)
noexcept {
90template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
91[[nodiscard]]
constexpr Enum
operator&(Enum lhs, Enum rhs)
noexcept {
92 return detail::FromUnderlying<Enum>(detail::ToUnderlying(lhs) & detail::ToUnderlying(rhs));
98template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
99constexpr Enum&
operator&=(Enum& lhs, Enum rhs)
noexcept {
constexpr Enum operator|(Enum lhs, Enum rhs) noexcept
constexpr Enum & operator&=(Enum &lhs, Enum rhs) noexcept
Sets lhs with logical AND between lhs and rhs.
constexpr Enum operator&(Enum lhs, Enum rhs) noexcept
constexpr Enum & operator|=(Enum &lhs, Enum rhs) noexcept
Sets lhs with logical OR between lhs and rhs.
Trait type that should be specialized for an enumeration to enable use of bitwise operators.