Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 变量模板-Clang和GCC再次不同_C++_Templates_C++11_Variadic Templates_Overload Resolution - Fatal编程技术网

C++ 变量模板-Clang和GCC再次不同

C++ 变量模板-Clang和GCC再次不同,c++,templates,c++11,variadic-templates,overload-resolution,C++,Templates,C++11,Variadic Templates,Overload Resolution,再次使用可变模板: template <typename... Ts1> constexpr bool ends_with_int(Ts1... ts1) { return false; } template <typename... Ts1> constexpr bool ends_with_int(Ts1... ts1, int i) { return true; } int main() { std::cout << std:

再次使用可变模板:

template <typename... Ts1>
constexpr bool ends_with_int(Ts1... ts1) {
    return false;
}

template <typename... Ts1>
constexpr bool ends_with_int(Ts1... ts1, int i) {
    return true;
}

int main() {
    std::cout << std::boolalpha;
    std::cout << ends_with_int(1, 2, 3) << std::endl;   
    std::cout << ends_with_int<int, int, int>(1, 2, 3) << std::endl;
    std::cout << ends_with_int(3) << std::endl;
    // below is very similar to the spec example at 14.8.2.1/1
    std::cout << ends_with_int<int, int>(1, 2, 3) << std::endl;
}
模板
constexpr bool以int结尾(Ts1…Ts1){
返回false;
}
模板
constexpr bool以int结尾(Ts1…Ts1,int i){
返回true;
}
int main(){
std::cout再看一次,gcc和clang都同意模板推导,他们在第二个函数:
以int结尾(Ts1…Ts1,int i)
是否比第一个函数:
以int结尾(Ts1…Ts1)
的问题上有所不同。对我来说,答案似乎是肯定的,第二个函数肯定更专业(和包在末尾时一样:)。所以我相信clang就在这里,它是一个gcc错误。
|---|---------------------------------------------------------------|
| # | ends_with_int                     | clang (3.8) | g++ (6.1)   |
|---|-----------------------------------|-------------|-------------|
| 1 |1, 2, 3                            |  false      |  false      |
|---|---------------------------------------------------------------|
| 2 |<int, int, int>(1, 2, 3)           |  false      |  false      |
|---|---------------------------------------------------------------|
| 3 | 3                                 |  true       |  ambiguity  |
|---|---------------------------------------------------------------|
| 4 |<int, int>(1, 2, 3)                |  true       |  ambiguity  |
|---|---------------------------------------------------------------|
template<class T1, class ... Types> void g1(Types ..., T1);

void h(int x, float& y) {
  const int z = x;
  g1(x, y, z);                 // error: Types is not deduced
  g1<int, int, int>(x, y, z);  // OK, no deduction occurs
}