How to instantiate template function with parameter pack arguments? [duplicate]

  arguments, c++, fold-expression, instantiation, templates

I have a function template declaration in a .h file as follows:

template <typename ... T> void f(T&... t);

The implementation in a .cpp file as follows:

template <typename ... T> void f(T&... t)
{
  // do something
}

I’d like to call this function from a different .cpp file as follows:

std::map<int, std::string> intMap = {{1, "one"}, {2, "two"}, {3, "three"}};
std::map<float, std::string> floatMap = {{1.0, "one"}, {2.0, "two"}};

f(intMap, floatMap);

But this doesn’t compile and I get the following error:

no instance of function template matches the argument list and object
(the object has type qualifiers that prevent a match)

How can I instantiate this template function so that I can use it as described above?

Thanks!

Source: Windows Questions C++

LEAVE A COMMENT