I'm attempting to maintain some code with variadic template functions that seems to work perfectly in GCC but fails in MSVC. I'm not very comfortable with this type of functions, but I have been able to reduce the problem to the following
#include <vector>
template<
template<typename...> class Container1>
std::vector<int> process(Container1<int> c)
{}
int main() {
std::vector<int> vectorOfInts;
process(vectorOfInts);
}
The real code is more complicated and the function takes more arguments, but the error is the same. The process
function is supposed to take several collections of some type and output a vector containing some of the elements.
The code compiles in GCC 7.2.0 but fails in MSVC 19.27.29112 with the following error:
test.cpp(10): error C2672: 'process': no matching overloaded function found
test.cpp(10): error C2784: 'std::vector<int,std::allocator<int>> process(Container1<int>)': could not deduce template argument for 'Container1<int>' from 'std::vector<int,std::allocator<int>>'
test.cpp(5): note: see declaration of 'process'
After extensive searching, the only thing I've been able to come up with are some bug reports for MSVC that are reportedly fixed. Does anyone have a suggestion for what could be the issue here, and how to work around it?
Thanks!
The workaround is to pass in the template parameters that std::vector
wants.
template<
template<typename...> class Container1,
typename... Rest>
std::vector<int> process(Container1<int, Rest...> c);