CppCommon  1.0.4.1
C++ Common Library
Classes | Namespaces | Macros
flags.h File Reference

Enum-based flags definition. More...

#include <bitset>
#include <type_traits>
#include "flags.inl"

Go to the source code of this file.

Classes

struct  CppCommon::IsEnumFlags< TEnum >
 Enum-based flags false checker. More...
 
class  CppCommon::Flags< TEnum >
 Enum-based flags. More...
 

Namespaces

 CppCommon
 C++ Common project definitions.
 

Macros

#define ENUM_FLAGS(type)
 Register a new enum-based flags macro. More...
 

Detailed Description

Enum-based flags definition.

Author
Ivan Shynkarenka
Date
25.08.2016

Definition in file flags.h.

Macro Definition Documentation

◆ ENUM_FLAGS

#define ENUM_FLAGS (   type)
Value:
using CppCommon::operator&;\
using CppCommon::operator|;\
using CppCommon::operator^;\
namespace CppCommon {\
template <> struct IsEnumFlags<type> : std::true_type {};\
}
C++ Common project definitions.
Definition: token_bucket.h:15

Register a new enum-based flags macro.

Should be used to get access to AND/OR/XOR logical operators with a given enum values.

Example:

enum class MyFlags
{
None = 0x0,
One = 0x1,
Two = 0x2,
Three = 0x4,
Four = 0x8
};
ENUM_FLAGS(MyFlags)
int main()
{
auto mask = MyFlags::One | MyFlags::Two;
if (mask & MyFlags::Two)
{
...
}
}
#define ENUM_FLAGS(type)
Register a new enum-based flags macro.
Definition: flags.h:48
Examples
common_flags.cpp.

Definition at line 48 of file flags.h.