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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With