I'm in a need for some sort of a type trait:
template<typename T> struct foo {};
template<>
struct foo<char> { static constexpr char c = 'c' };
This works perfectly if I need a character c
of the type char
, but doesn't in the following case:
printf("%c", foo<const char>::c);
Is there a more elegant way to do this, rather than specify the template for both char
and const char
in the same way?
Add a partial specialization:
template <class T> struct foo<const T> : foo<T> {};
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