Skip to content

Write an example flags scheme that doesn't use sm::flags #128

@sebsjames

Description

@sebsjames

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions