9#ifndef CPPCOMMON_FLAGS_H
10#define CPPCOMMON_FLAGS_H
18template <
typename TEnum>
48#define ENUM_FLAGS(type)\
49using CppCommon::operator&;\
50using CppCommon::operator|;\
51using CppCommon::operator^;\
53template <> struct IsEnumFlags<type> : std::true_type {};\
63template <
typename TEnum>
67 typedef typename std::make_unsigned<typename std::underlying_type<TEnum>::type>::type type;
78 { _value =
value;
return *
this; }
80 { _value = (type)
value;
return *
this; }
95 { _value &=
flags._value;
return *
this; }
97 { _value |=
flags._value;
return *
this; }
99 { _value ^=
flags._value;
return *
this; }
134 template <
typename UEnum>
Flags & operator|=(const Flags &flags) noexcept
bool isset(TEnum value) const noexcept
Is the given flag set?
bool isset(type value) const noexcept
Is the given flag set?
friend void swap(Flags< UEnum > &flags1, Flags< UEnum > &flags2) noexcept
std::bitset< sizeof(type) *8 > bitset() const noexcept
Get the bitset value.
friend Flags operator|(const Flags &flags1, const Flags &flags2) noexcept
Flags & operator=(const Flags &) noexcept=default
Flags(TEnum value) noexcept
void swap(Flags &flags) noexcept
Swap two instances.
friend bool operator!=(const Flags &flags1, const Flags &flags2) noexcept
Flags & operator=(TEnum value) noexcept
type underlying() const noexcept
Get the underlying enum value.
friend Flags operator&(const Flags &flags1, const Flags &flags2) noexcept
Flags logical friend operators.
bool isset() const noexcept
Is any flag set?
TEnum value() const noexcept
Get the enum value.
Flags operator~() const noexcept
Reverse all flags.
Flags & operator=(Flags &&) noexcept=default
Flags(type value) noexcept
Flags & operator&=(const Flags &flags) noexcept
Flags logical assign operators.
Flags & operator^=(const Flags &flags) noexcept
Flags(const Flags &) noexcept=default
friend Flags operator^(const Flags &flags1, const Flags &flags2) noexcept
bool operator!() const noexcept
Is no flag set?
friend bool operator==(const Flags &flags1, const Flags &flags2) noexcept
Flags(Flags &&) noexcept=default
Enum-based flags inline implementation.
C++ Common project definitions.
Enum-based flags false checker.