Question

I created small class that allows me to use enumerators of strongly-typed enums as flags (in combination). I'm using type_traits for underlying type detection so it should be also slightly type safe and mostly processed at compile time. However, i was wondering if it is really worth it.

I can now write something like

void Foo(Flags<Mode> Value);

and the programmer will see that he can use only enumerators from Mode (e.g. Mode::Read) and also he can't combine any other enums with Mode. Do you think it is better way than

void Foo(int Mode);

, i'm not sure if people can appreciate it?

Was it helpful?

Solution

What you are suggesting is considered best practice.

With a modern optimizing compiler there should be no performance cost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top