输入`type`和`const type`的特征

Jyt*_*tug 4 c++ templates

我需要一些类型特征:

template<typename T> struct foo {};
template<>
struct foo<char> { static constexpr char c = 'c' };
Run Code Online (Sandbox Code Playgroud)

如果我需要c该类型的字符,这可以完美地工作char,但在以下情况下不是这样:

printf("%c", foo<const char>::c);
Run Code Online (Sandbox Code Playgroud)

有没有更优雅的方式来做到这一点,而不是指定两个模板char,并const char以同样的方式?

T.C*_*.C. 5

添加部分专业化:

template <class T> struct foo<const T> : foo<T> {};
Run Code Online (Sandbox Code Playgroud)