OpenEnroth 73e68f7
|
#include <Flags.h>
Classes | |
struct | Dummy |
Public Types | |
using | enumeration_type = Enum |
using | underlying_type = std::underlying_type_t< Enum > |
Public Member Functions | |
constexpr | Flags (std::nullptr_t=0) |
constexpr | Flags (enumeration_type value) |
constexpr | Flags (underlying_type value) |
constexpr | operator underlying_type () const |
constexpr Flags & | operator&= (Flags mask) |
constexpr Flags & | operator&= (enumeration_type mask) |
constexpr Flags & | operator|= (Flags flags) |
constexpr Flags & | operator|= (enumeration_type flags) |
constexpr Flags | operator~ () const |
constexpr bool | operator! () const |
constexpr | operator fake_bool () const |
Private Types | |
using | fake_bool = void(*)(Dummy *) |
Static Private Member Functions | |
static void | fake_true (Dummy *) |
Private Attributes | |
underlying_type | _value |
Friends | |
constexpr friend Flags | operator| (Flags l, Flags r) |
constexpr friend Flags | operator| (enumeration_type l, Flags r) |
constexpr friend Flags | operator| (Flags l, enumeration_type r) |
constexpr friend Flags | operator& (Flags l, Flags r) |
constexpr friend Flags | operator& (enumeration_type l, Flags r) |
constexpr friend Flags | operator& (Flags l, enumeration_type r) |
constexpr friend bool | operator== (Flags l, Flags r) |
constexpr friend bool | operator== (enumeration_type l, Flags r) |
Flags
is basically an analog of QFlags
from Qt, a type-safe wrapper for flags defined in enumerations.
Example usage:
|
inlineconstexpr |
|
inlineexplicitconstexpr |
Implicit operator bool with some dark magic on top.
Explicit operator bool doesn't work here because then we can't just write return flags & SOME_FLAG
in a function returning bool
.
Implicit operator bool allows to do arithmetic on top of the returned result, so something like return flags == 0x16
actually compiles, albeit in a totally unexpected way (comparing bool
to 0x16
always returns false).
Thus the solution with a function pointer.
|
inlineexplicitconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |