문제

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?

도움이 되었습니까?

해결책

What you are suggesting is considered best practice.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top