I have a template class that takes a string literal as parameter. The code works fine - but I've got one question, whether it is possible to use compile-time check to skip the generating of if (S)
or else
block body at all? (Something like the __if_exists or #if, traits, etc). I understand that I could have a specialized A<nullptr>
that defines a different print()
function, but also want to know whether there's other (more simple) ways of doing this. Thanks!
template<char const* S = nullptr>
class A
{
public:
void print()
{
if (S)
cout << S << endl;
else
cout << "nullptr" << endl;
}
};