Domanda

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?

È stato utile?

Soluzione

What you are suggesting is considered best practice.

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top