Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to template based on enums?

I am writing a unique ID generator which has different strategies for generating Id's which are unique through a day, or a week or a month. I do not want to create a hierarchy of classes with virtual function mechanism

Is doing something like the below code snippet, a good idea? Any suggestions?

enum Duration { Day, Week, Month };

template <Duration d>
class IDGenerator
{
   generateId();
}
like image 972
Aditya Avatar asked Jun 29 '11 09:06

Aditya


1 Answers

Yes it acceptable and will work just file if compile-time polymorphism is enough for you - you will save on virtual calls and that will allow for better compiler coptimizations.

like image 176
sharptooth Avatar answered Sep 30 '22 19:09

sharptooth