Is this a good idea for an enumeration based template?

I am writing a unique identifier generator that has different strategies for generating an identifier that are unique every other day or week or month. I do not want to create a class hierarchy with a virtual function mechanism

Does something like the code snippet below, good idea? Any suggestions?

enum Duration { Day, Week, Month }; template <Duration d> class IDGenerator { generateId(); } 
+6
source share
2 answers

Yes, this is acceptable and will only work with a file if compilation time polymorphism is enough for you. - You will save on virtual calls, which will allow you to better understand compilers.

+5
source

As it stands taller, it is uselessly confusing. Just create three classes with different names.

-1
source

Source: https://habr.com/ru/post/891625/


All Articles