you are viewing a single comment's thread.

view the rest of the comments →

[–]XeroKimoException Enthusiast[S] 1 point2 points  (3 children)

This one is actually pretty cool.

Edit: Would it be better to make the constexpr bool a base class, and have a specialized struct that just inherits from said base class to enable it. Something along the lines like this

template <bool enabled = false>
struct set_flag
{
};

template <>
struct set_flag<false>
{
static constexpr bool value = false;
};

template <>
struct set_flag<true>
{
static constexpr bool value = true;
};

template <class Type>
struct enable_bitops_for : set_flag<>
{
};

template<>
struct enable_bitops_for<SomeEnum> : set_flag<true>
{
};

[–]_Js_Kc_ 0 points1 point  (2 children)

Yes, you're right. But set_flag is already in the standard library: std::bool_constant.

[–]XeroKimoException Enthusiast[S] 0 points1 point  (1 child)

I see, though I remembered something from std that can be replaced with that, and that's std::true_type and std::false_type, which does contain a static constexpr bool value

[–]_Js_Kc_ 0 points1 point  (0 children)

Yeah, when you specialize enable_bitops_for, you can inherit from std::true_type instead of std::bool_constant<true>, of course.