在研究这个答案时,我发现使用参数包的模板不会被期望有特定数量参数的模板所接受。
在我看来,这是一个缺陷,因为如果一个模板可以接受任意数量的参数,它应该能够映射到一个特定的数字。有没有语言律师能解释为什么不允许这样做?
下面是一个简单的例子:
template <typename...Ts>
using pack = void;
template <template <typename> class>
using accept_template = int;
accept_template<pack> value = 0;当然,我不会在这种情况下使用它。它将用于将模板传递给另一个模板,该模板将以某种方式使用传递的模板。在我联系的答案中,我提出了一个解决办法,但我仍然觉得这是一个缺陷。
发布于 2017-12-09 17:52:05
由于P0522引入了新的规则来处理模板参数匹配模板参数的问题,这种限制被放松了。因此,从文件中:
template<class T, class U = T> class B { /* ... */ };
template <class ... Types> class C { /* ... */ };
template<template<class> class P> class X { /* ... */ };
X<B> xb; // OK, was ill-formed:
// default arguments for the parameters of a template argument are ignored
X<C> xc; // OK, was ill-formed:
// a template parameter pack does not match a template parameter您的示例无法在C++14中编译,但将在C++17中编译。
https://stackoverflow.com/questions/47731088
复制相似问题