Template template parameters and variadic templates with gcc 4.4

前端 未结 2 1676
情深已故
情深已故 2021-01-11 12:47

I\'m using gcc 4.4 on Debian squeeze. Consider the following code.

#include 
#include 
using std::map;
using std::string;

// Args l         


        
2条回答
  •  太阳男子
    2021-01-11 13:53

    I don't think variadic template parameters can match non-variadic arguments in g++4.4, so you need to overload your foo function with a non-variadic version.

    Also keep in mind that map actually has more than two template parameters, and therefor wont match the new foo-function either.

    This addition to your example should clarify it:

    #include 
    #include 
    using std::map;
    using std::string;
    
    // Args lets the user specify additional explicit template arguments
    template  class C,
              typename... Args>
    C foo() {
      C x;
      return x;
    }
    
    template class C, typename Arg>
    C foo() {
      return C();
    }
    
    template class A {};
    
    template class B {};
    
    int main(void) {
      map a = foo(); // fails.
      A x = foo();
      B y = foo();
    }
    

提交回复
热议问题