Is it a good idea to template based on enums?
I am writing a unique ID generator which has different strategies for genera开发者_开发技巧ting 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();
}
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.
As it stands above, it is needlessly confusing. Just create three classes with different names.
精彩评论