template<class T, typename std::underlying_type<T>::type fullValue = typename std::underlying_type<T>::type(~0)>
Corrade::Containers::EnumSet class

Set of enum values.

Template parameters
T Enum type
fullValue All enum values together. Defaults to all bits set to 1.

Provides strongly-typed set-like functionality for strongly typed enums, such as binary OR and AND operations. The only requirement for enum type is that all the values must be binary exclusive.

Desired usage is via typedef'ing. You should also call CORRADE_ENUMSET_OPERATORS() macro with the resulting type as parameter to have out-of-class operators defined:

enum class Feature: unsigned int {
    Fast = 1 << 0,
    Cheap = 1 << 1,
    Tested = 1 << 2,
    Popular = 1 << 3
};

typedef Containers::EnumSet<Feature> Features;
CORRADE_ENUMSET_OPERATORS(Features)

If you have the EnumSet as private or protected member of any class, you have to declare the out-of-class operators as friends. It can be done with CORRADE_ENUMSET_FRIEND_OPERATORS() macro:

class Application {
    private:
        enum class Flag: unsigned int {
            Redraw = 1 << 0,
            Exit = 1 << 1
        };

        typedef Containers::EnumSet<Flag> Flags;
        CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)
};

CORRADE_ENUMSET_OPERATORS(Application::Flags)

One thing these macros cannot do is to provide operators for enum sets inside templated classes. If the enum values are not depending on the template, you can work around the issue by declaring the enum in some hidden namespace outside the class and then typedef'ing it back into the class:

namespace Implementation {
    enum class ObjectFlag: unsigned int {
        Dirty = 1 << 0,
        Marked = 1 << 1
    };

    typedef Containers::EnumSet<ObjectFlag> ObjectFlags;
    CORRADE_ENUMSET_OPERATORS(ObjectFlags)
}

template<class T> class Object {
    public:
        typedef Implementation::ObjectFlag Flag;
        typedef Implementation::ObjectFlags Flags;
};

Public types

enum (anonymous): UnderlyingType { FullValue = fullValue }
using Type = T
Enum type.
using UnderlyingType = std::underlying_type<T>::type
Underlying type of the enum.

Constructors, destructors, conversion operators

EnumSet() constexpr
Create empty set.
EnumSet(T value) constexpr
Create set from one value.
EnumSet(NoInitT) explicit
Create uninitialized set.
operator bool() const explicit constexpr
Value as boolean.
operator UnderlyingType() const explicit constexpr
Value in underlying type.

Public functions

auto operator==(EnumSet<T, fullValue> other) const -> bool constexpr
Equality operator.
auto operator!=(EnumSet<T, fullValue> other) const -> bool constexpr
Non-equality operator.
auto operator>=(EnumSet<T, fullValue> other) const -> bool constexpr
Whether other is subset of this.
auto operator<=(EnumSet<T, fullValue> other) const -> bool constexpr
Whether other is superset of this.
auto operator|(EnumSet<T, fullValue> other) const -> EnumSet<T, fullValue> constexpr
Union of two sets.
auto operator|=(EnumSet<T, fullValue> other) -> EnumSet<T, fullValue>&
Union two sets and assign.
auto operator&(EnumSet<T, fullValue> other) const -> EnumSet<T, fullValue> constexpr
Intersection of two sets.
auto operator&=(EnumSet<T, fullValue> other) -> EnumSet<T, fullValue>&
Intersect two sets and assign.
auto operator^(EnumSet<T, fullValue> other) const -> EnumSet<T, fullValue> constexpr
XOR of two sets.
auto operator^=(EnumSet<T, fullValue> other) -> EnumSet<T, fullValue>&
XOR two sets and assign.
auto operator~() const -> EnumSet<T, fullValue> constexpr
Set complement.

Enum documentation

template<class T, typename std::underlying_type<T>::type fullValue>
enum Corrade::Containers::EnumSet<T, fullValue>::(anonymous): UnderlyingType

Enumerators
FullValue

All enum values together

Function documentation

template<class T, typename std::underlying_type<T>::type fullValue>
Corrade::Containers::EnumSet<T, fullValue>::EnumSet(NoInitT) explicit

Create uninitialized set.

The contents are left in undefined state.

template<class T, typename std::underlying_type<T>::type fullValue>
bool Corrade::Containers::EnumSet<T, fullValue>::operator>=(EnumSet<T, fullValue> other) const constexpr

Whether other is subset of this.

Equivalent to (a & other) == other.

template<class T, typename std::underlying_type<T>::type fullValue>
bool Corrade::Containers::EnumSet<T, fullValue>::operator<=(EnumSet<T, fullValue> other) const constexpr

Whether other is superset of this.

Equivalent to (a & other) == a.

template<class T, typename std::underlying_type<T>::type fullValue> template<class T, typename std::underlying_type<T>::type fullValue>
Utility::Debug& enumSetDebugOutput(Utility::Debug& debug, EnumSet<T, fullValue> value, const char* empty, std::initializer_list<T> enums)

Print enum set to debug output.

Parameters
debug Debug output
value Value to be printed
empty What to print in case of an empty enum set
enums Recognized enum values

Assuming underlying enum type has already implemented operator<< for Utility::Debug, this function is able to print value of given enum set. Example definition:

enum class Feature: unsigned int {
    Fast = 1 << 0,
    Cheap = 1 << 1,
    Tested = 1 << 2,
    Popular = 1 << 3
};

// already defined to print values as e.g. Feature::Fast and Features(0xabcd)
// for unknown values
Utility::Debug& operator<<(Utility::Debug&, Feature);

typedef Containers::EnumSet<Feature> Features;
CORRADE_ENUMSET_OPERATORS(Features)

Utility::Debug& operator<<(Utility::Debug& debug, Features value) {
    return Containers::enumSetDebugOutput(debug, value, "Features{}", {
        Feature::Fast,
        Feature::Cheap,
        Feature::Tested,
        Feature::Popular});
}

The usage would be then straightforward:

// prints Feature::Fast|Feature::Cheap
Utility::Debug{} << (Feature::Fast|Feature::Cheap);

// prints Feature::Popular|Feature(0xdead)
Utility::Debug{} << (Feature::Popular|Feature(0xdead));

// prints Features{}
Utility::Debug{} << Features{};