Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- enum class a_t { a1, a2, a3, a4 };
- enum class b_t { };
- enum class c_t { };
- // Make a collection of types we want to define an operator| for.
- enum typename or_types_t {
- a_t, c_t
- };
- // Loop over each enumerator in or_types_t.
- @meta for enum(auto e : or_types_t) {
- // Define the function that takes two parameters with the associated type
- // and returns a result of the associated type.
- @enum_type(e) operator|(@enum_type(e) lhs, @enum_type(e) rhs) {
- typedef @enum_type(e) type_t;
- static_assert(std::is_enum<type_t>::value);
- typedef std::underlying_type<type_t>::type underlying_t;
- return (type_t)((underlying_t)lhs | (underlying_t)rhs);
- }
- }
- int main() {
- a_t a = a_t::a2 | a_t::a4;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement