1

VisualStudio can not compile this code (error C2976)

but GCC and Clang can compile this code

why???

#include <iostream>
#include <map>

template <typename... ARGS>
void Func(const std::map<ARGS...>& m)
{
    //...
}

template <typename T>
void Func(const T& t)
{
    //...
}

int main()
{
    std::map<int, double> m;
    Func(m);    // error C2976: 'std::map': too few template arguments
    Func(123);  // OK
    return 0;
}
Karpediem
  • 11
  • 1
  • 1
    Does it show any error? – Guy Ben Hemo Apr 30 '16 at 15:34
  • 1
    Possible duplicate of [Template deduction fails for std:map as template parameter](http://stackoverflow.com/questions/26059219/template-deduction-fails-for-stdmap-as-template-parameter) – cromod Apr 30 '16 at 16:07

1 Answers1

1

My guess is that this is because Visual Studio 2015 doesn't fully support nested variadic templates, and it can't deduce the type correctly.

As a work around you have to specify the types explicitly, so you may use Func<std::map<int, double>>(m);, Func<int, double>(m); or even Func<decltype(m)>(m); (I recommend the last one).

Rakete1111
  • 47,013
  • 16
  • 123
  • 162