开发者

Is it a good idea to template based on enums?

开发者 https://www.devze.com 2023-03-16 16:20 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消