CppCommon  1.0.4.1
C++ Common Library
common_flags.cpp

Enum-based flags example

#include "common/flags.h"
#include <iostream>
enum class MyFlags
{
None = 0x0,
One = 0x1,
Two = 0x2,
Three = 0x4,
Four = 0x8
};
// Register enum as flags to enable AND/OR/XOR logical operators with enum values!
ENUM_FLAGS(MyFlags)
int main(int argc, char** argv)
{
auto mask = MyFlags::One | MyFlags::Two | MyFlags::Three;
if (mask & MyFlags::One)
std::cout << "MyFlags::One is set" << std::endl;
if (mask & MyFlags::Two)
std::cout << "MyFlags::Two is set" << std::endl;
if (mask & MyFlags::Three)
std::cout << "MyFlags::Three is set" << std::endl;
if (mask & MyFlags::Four)
std::cout << "MyFlags::Four is set" << std::endl;
return 0;
}
Enum-based flags definition.
#define ENUM_FLAGS(type)
Register a new enum-based flags macro.
Definition: flags.h:48