I have a requirement that, I should use a specific class if an integer passed as one of the template parameter is greater than a certain value. Otherwise, I should get a compile time error…
It is something like the following:
enum Time { Day, Week, Month };
template<Time t, int length>
class Timer
{
}
Now, I have to restrict instantiating Timer in such a way that –
Timer<Day,8> , Timer<Day,9> etc should work, but length cannot be less than 8 when used with Day.
Similarly, length cannot be less than 10 when used with Week and so on…
Can someone please help me out with how this can be achieved at compile-time?
Pass the result of
length >= 8as abooltemplate argument to helper template. Provide specialization fortrueonly. Having said that, this sounds like homework, so I’ll leave the coding to you.Cheers & hth.