You can do C-style flags in C++ like this:
namespace flag
{
constexpr std::uint32_t a = 0x1;
constexpr std::uint32_t b = 0x2;
constexpr std::uint32_t c = 0x4;
}
std::uint32_t state = 0x0;
state |= flag::a;
state ^= flag::b;
if (state & flag::c) { }
This should be exactly as performant/simple/small as the C scheme. It has the benefit of named flag values (flag::a in the example). It does require that the programmer correctly sets the constexpr values 0x1, 0x2, 0x4, etc instead of 1, 2, 3.
You can do C-style flags in C++ like this:
This should be exactly as performant/simple/small as the C scheme. It has the benefit of named flag values (
flag::ain the example). It does require that the programmer correctly sets the constexpr values 0x1, 0x2, 0x4, etc instead of 1, 2, 3.