Boost logo

Boost Users :

Subject: [Boost-users] Flags for strongly typed enum?
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-12-11 04:14:21


Hi there,

Is there any library in Boost that provides type-safe enum bit flags?

Something like below:

    enum class option
    {
        a = 1, b = 2, c = 4, ....
    };

    DEFINE_FLAGS(options, option);

    options set1 = option::a | option::b;
    options set2 = set1 | option::c;
    options err1 = option::a | 2; // error
    options err2 = set2 | 2; // error

    if (set1 & option::a) {...}
    if (set1 & 2) {...} // error

Thanks.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net