vcvarsall.batVisual Studio 2019(预览版和未来版本)的文件位置是什么?
似乎它与 VS 2017 不同“C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat”
如果我有一个看起来像这样的模板,为了示例而执行简单的复制操作,但对于std::mapand std::unordered_map:
template<typename T1, typename T2>
inline std::map<T1, T2> map_copy(std::map<T1,T2> const& a) {
std::map<T1,T2> output;
output = a;
return output;
}
template<typename T1, typename T2>
inline std::unordered_map<T1, T2> map_copy(std::unordered_map<T1,T2> const& a) {
std::unordered_map<T1,T2> output;
output = a;
return output;
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法(可能使用 C++ 概念)将这些定义简化为一个,将可能的类型限制为std::map和std::unordered_map?
如果您有以下过滤列表模板:
template <typename T>
inline std::list<T> list_filter(std::list<T> const& a, bool (f)(T)) {
std::list<T> output;
std::copy_if(a.begin(), a.end(), std::back_inserter(output), f);
return output;
}
Run Code Online (Sandbox Code Playgroud)
然后尝试使用里面的 lambda 调用它,例如:
std::list<int> lst = {1,2,3,4,5};
auto filtered = list_filter(lst, [](int el) -> bool { return (el % 2 == 0); });
Run Code Online (Sandbox Code Playgroud)
它将产生错误no matching function for call to list_filter(..., std::__cxx11::list<int>)::<lambda(int)>)'。
有没有办法绕过这个限制而不将 lambda 提取到单独的函数中?为什么 C++ 不允许这种明显的模式?
c++ lambda templates functional-programming template-argument-deduction