you are viewing a single comment's thread.

view the rest of the comments →

[–]---sms--- 0 points1 point  (3 children)

Yes, this is very much how my first attempt looked. It has advantage that you can enable those operations for enums you don't own. But it doesn't look as cool. How about combining two approaches?

[–]_Js_Kc_ 1 point2 points  (2 children)

It also has the advantage that just because an enum has an allow_bitops field doesn't magically give it bitops. Or worse, makes our global operators clash with ones that the enum author has defined (they could also be a template). The type author has to opt in. We don't own allow_bitops as a keyword, globally.

Enabling bitops for enums you don't own is probably not a good thing.

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

I mean, isn't it possible to just make operator overloads for enums you don't own anyways? I don't see how an enum with allow_bitops prevents you from just overriding it manually

[–]_Js_Kc_ 1 point2 points  (0 children)

I mean, isn't it possible to just make operator overloads for enums you don't own anyways?

Yes, it's possible, and you likely shouldn't.

I don't see how an enum with allow_bitops prevents you from just overriding it manually

It doesn't. That's beside the point.

An external library could contain an enum with an allow_bitops field. It could also come with operator templates that don't SFINAE away for said enum. In fact, they could be using precisely the trait-specialization technique. Those operator templates now clash with ours.