Ambiguity error in C++17 (template template parameters and default arguments issue)

前端 未结 1 1887
栀梦
栀梦 2021-02-12 04:04

I have code which is differently interpreted by g++ with the c++14 and c++17 standard flags:

#include 
#include 

        
1条回答
  •  梦毁少年i
    2021-02-12 04:18

    The behavior changed since C++17.

    Before C++17, the code works because std::vector has two template parameters (the 2nd one has the default argument std::allocator), while the template template parameter Vector is declared to have only one, they don't match then the 2nd func won't be considered.

    Since C++17 (CWG 150), the default template arguments are allowed for a template template argument to match a template template parameter with fewer template parameters. That means both func become valid candidates and then leads to ambiguity.

    template class A { /* ... */ };
    template class B { /* ... */ };
    
    template class P> class X { /* ... */ };
    
    X xa; // OK
    X xb; // OK in C++17 after CWG 150
             // Error earlier: not an exact match
    

    0 讨论(0)
提交回复
热议问题