'what is the best way to enable bitwise-or on enum *class* members?

So far I have:

#include <cstdint>

enum class le_enum : uint32_t {
    FLAG_0 = 0x00000000,
    FLAG_1 = 0x00000001,
    FLAG_2 = 0x00000002,
    FLAG_3 = 0x00000004,
    FLAG_4 = 0x00000008,
    FLAG_5 = 0x00000010,
    FLAG_6 = 0x00000020,
    FLAG_7 = 0x00000040
};

inline uint32_t operator|(const le_enum lhs, const le_enum rhs) {
    return (uint32_t)lhs | (uint32_t)rhs;
}

inline uint32_t operator|(const uint32_t lhs, const le_enum rhs) {
    return lhs | (uint32_t)rhs;
}

int main(int argc, char** argv) {

    uint32_t flags = le_enum::FLAG_0 | le_enum::FLAG_7;
    uint32_t flags2 = le_enum::FLAG_2 | le_enum::FLAG_3 | le_enum::FLAG_5;

    return 0;
}

where I need to define 2 operators.

Can I enable this with with less code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source