MSVC 可变参数模板处理错误?
Error in MSVC variadic template handling?
我正在尝试使用可变模板函数维护一些代码,这些代码似乎在 GCC 中运行良好但在 MSVC 中失败。我对这种类型的功能不太满意,但我已经能够将问题减少到以下
#include <vector>
template<
template<typename...> class Container1>
std::vector<int> process(Container1<int> c)
{}
int main() {
std::vector<int> vectorOfInts;
process(vectorOfInts);
}
真正的代码更复杂,函数的参数也更多,但错误是一样的。 process
函数应该采用某种类型的多个集合并输出包含某些元素的向量。
代码在 GCC 7.2.0 中编译但在 MSVC 19.27.29112 中失败并出现以下错误:
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'
经过大量搜索,我唯一能想到的是一些据报道已修复的 MSVC 错误报告。有人对这里可能出现的问题以及如何解决它有什么建议吗?
谢谢!
解决方法是传入std::vector
想要的模板参数。
template<
template<typename...> class Container1,
typename... Rest>
std::vector<int> process(Container1<int, Rest...> c);
我正在尝试使用可变模板函数维护一些代码,这些代码似乎在 GCC 中运行良好但在 MSVC 中失败。我对这种类型的功能不太满意,但我已经能够将问题减少到以下
#include <vector>
template<
template<typename...> class Container1>
std::vector<int> process(Container1<int> c)
{}
int main() {
std::vector<int> vectorOfInts;
process(vectorOfInts);
}
真正的代码更复杂,函数的参数也更多,但错误是一样的。 process
函数应该采用某种类型的多个集合并输出包含某些元素的向量。
代码在 GCC 7.2.0 中编译但在 MSVC 19.27.29112 中失败并出现以下错误:
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'
经过大量搜索,我唯一能想到的是一些据报道已修复的 MSVC 错误报告。有人对这里可能出现的问题以及如何解决它有什么建议吗?
谢谢!
解决方法是传入std::vector
想要的模板参数。
template<
template<typename...> class Container1,
typename... Rest>
std::vector<int> process(Container1<int, Rest...> c);