内容简介:http://stackoverflow.com/questions/41062333/what-exactly-is-a-trailing-parameter-pack
).在这个网站上,我们也了解到
In case of a tie, if one function template has a trailing parameter pack and the other does not, the one with the omitted parameter is considered to be more specialized than the one with the empty parameter pack.
现在,我不知道什么是一个尾随的参数包.如果有的话
template<class ...> struct tuple { /* ... */ };
template<class T, class...Ts> void foo(tuple<T,Ts...>);
template<class T, class...Ts> void bar(T, Ts...);
是和哪些不是为什么?请注意,cl ang考虑
template<class T> void f(tuple<T>);
template<class T, class...Ts> void f(tuple<T,Ts...>);
int main()
{ f(tuple<int>()); } // ambiguous call?
含糊不清,这意味着foo没有拖尾参数包.
.以下内容添加到[temp.deduct.partial]中:
…[if] function template F
is at least as specialized as function template G
and vice-versa, and if G
has a trailing parameter pack for which F
does not have a corresponding parameter, and if F
does not have a trailing parameter pack, then F
is more specialized than G
.
标准没有明确定义“尾随参数包”的含义,但是根据使用此术语的现有上下文进行判断,它是指在模板参数列表中显示为最右边参数的模板参数包:
template<class T, class... U> struct X; // ^^^^^^^^^^
或者,在函数参数列表中显示为最右边参数的函数参数包:
template<class T, class... U> void y(T, U...); // ^^^^
目前的草案仍然包含[temp.deduct.type]中的这个过时的例子:
template<class T, class... U> void f(T, U...); template<class T> void f(T); f(&i); // error: ambiguous
这个标准缺陷报告已经存在了几年, GCC 和 Clang 都已经实施了这个决议.他们都同意上面的例子是f的第二个重载的有效调用.
GCC和Clang不同意解决缺陷的范围.这是可以理解的,因为最近才更新了包括提出的标准措辞.在您的示例中,该包不会扩展到函数参数列表,而是扩展到函数参数类型的模板参数列表中:
template<class T, class... U> void g(tuple<T, U...>);
template<class T> void g(tuple<T>);
g(tuple<int>{});
GCC将其视为g的第二个重载的有效调用; ang ang把它看作是模糊的. Clang的正确性可能取决于“尾随参数包”是否包括尾随的模板参数包,或仅包括尾随函数参数包.
注意,两个编译器都同意C<int>是指在以下示例中类模板C的第二部分专业化:
template<class...> struct C;
template<class T, class... U> struct C<T, U...> {};
template<class T> struct C<T> {};
这在Clang中似乎是一个不一致的地方,因为类模板特殊化的部分 排序 的标准规则是根据函数模板的部分顺序来定义的.见 CWG1432 .
http://stackoverflow.com/questions/41062333/what-exactly-is-a-trailing-parameter-pack
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Programming Amazon Web Services
James Murty / O'Reilly Media / 2008-3-25 / USD 49.99
Building on the success of its storefront and fulfillment services, Amazon now allows businesses to "rent" computing power, data storage and bandwidth on its vast network platform. This book demonstra......一起来看看 《Programming Amazon Web Services》 这本书的介绍吧!