在Kona会议上,构造函数(P0091R0)的模板参数扣除已被批准。它简化了一些变量定义:初始化列表中的构造函数的模板参数扣除
std::pair p {1,2}; // o.k., constructor pair<int,int>(1,2)
std::vector v1 (10, 0); // o.k., 10 zeroes, constructor vector<int>(size_t n, T initvalue)
std::vector v2 {10, 0}; // o.k., 2 values: 10, 0, apparently initializer list?
std::vector v3 = {10, 0}; // o.k., same as v2?
但是,下面的线不会以GCC 7编译HEAD 201611版本(live example):
std::vector v4 = {3}; // error: no matching function for call to 'std::vector(int)'
std::vector v5 {1, 2, 3}; // error: 'int' is not a class
std::set s {1, 2, 3}; // error: no matching function for call to 'std::set(int,int,int)'
这些仅仅是 “遥远的桥”,因为它们涉及初始化列表? 它们是否覆盖了模板类型参数推导? 当编译器符合C++ 1z时,它们会被允许吗?
我认为你的“与v3相同?”是一个错字。 –
@John Zwinck:是的,谢谢,纠正。 –
最初的建议根本没有正确的措辞。我们有一些[大规模标准修复](https://github.com/cplusplus/draft/commit/954e86feae0c5cbb80c2c506fd5e3db4993bf60a)传入。 –