【发布时间】:2017-09-10 19:45:58
【问题描述】:
我刚开始学习模板,我正在浏览一个实现 TypeList 的示例,并看到了 TypeList 的 Length 方法的实现。
template <class TList> struct Length;
template <> struct Length<NullType>
{
enum { value = 0 };
};
template <class T, class U>
struct Length< Typelist<T, U> >
{
enum { value = 1 + Length<U>::value };
};
我的问题是主长度模板只有 1 个参数(TList),但专业化有 2 个参数。这怎么可能,我在其他地方读到,专业化的参数数量更少
【问题讨论】:
-
specialization 有 2 个参数,但只定义一种类型。
-
特化本身是一个带有两个参数的模板,但它仍然只为特化提供一种类型 (
Typelist<T, U>)。
标签: c++ templates partial-specialization loki