I have a requirement that I use a specific class if the integer passed as one of the template parameters is greater than a certain value. Otherwise, I should get a compile-time error ...
This is something like the following:
enum Time { Day, Week, Month };
template<Time t, int length>
class Timer
{
}
Now I need to limit the instantiation Timerin such a way that -
Timer<Day,8>, Timer<Day,9>etc., but lengthcannot be less than 8 when used with Day.
Similarly, lengthit cannot be less than 10 when used with Week, etc.
Can someone please help me on how this can be achieved at compile time?
source
share