10#ifndef NUMAPP_FLAGS_HPP_
11#define NUMAPP_FLAGS_HPP_
19#define NUMAPP_ENABLE_BITFLAG(enum) \
21 struct IsFlagEnum<enum> : std::true_type { \
22 static_assert(std::is_enum_v<enum>); \
29constexpr std::underlying_type_t<Enum> ToUnderlying(Enum value)
noexcept {
30 return static_cast<std::underlying_type_t<Enum>
>(value);
33constexpr Enum FromUnderlying(std::underlying_type_t<Enum> value)
noexcept {
34 return static_cast<Enum
>(value);
75template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
76[[nodiscard]]
constexpr Enum
operator|(Enum lhs, Enum rhs)
noexcept {
77 return detail::FromUnderlying<Enum>(detail::ToUnderlying(lhs) | detail::ToUnderlying(rhs));
83template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
84constexpr Enum&
operator|=(Enum& lhs, Enum rhs)
noexcept {
92template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
93[[nodiscard]]
constexpr Enum
operator&(Enum lhs, Enum rhs)
noexcept {
94 return detail::FromUnderlying<Enum>(detail::ToUnderlying(lhs) & detail::ToUnderlying(rhs));
100template <class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
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.