【发布时间】:2020-06-05 11:02:13
【问题描述】:
Visual Studio 2019 的最新 16.6 更新删除了 std::plus::result_type、std::minus::result_type 和相关的 typedef。 (它们在 C++17 中被弃用,在 C++20 中被删除。)代码的一个大大简化的版本如下所示:
template <typename FF>
struct function_wrapper {
function_wrapper(FF func, const std::string& name) : func_(func), name_(name) { }
int operator()(int i1, int i2) const { return func_(i1, i2); }
// ... other stuff ...
FF func_;
std::string name_;
};
template <typename FF>
int use_function(const function_wrapper<FF>& func, const std::pair<int, int>& args) {
return func(args.first, args.second);
}
funcWrapper<boost::function<int(int, int)>> plus_func(std::plus<int>(), "plus");
std::cout << use_function(plus_func, std::make_pair<int, int>(1, 2)) << std::endl;
更新后,这不再编译,产生错误:
boost\1.72.0\boost\bind\bind.hpp(75,25): error C2039: 'result_type': is not a member of 'std::plus<int>'
我无法将result_type typedef 添加回std::plus,因此我需要另一种方法来解决此问题。问题是,生成的代码也需要在 C++03 下编译,因此 lambdas 和 >=C++11 构造不是一个可行的选择。我可以重新实现 std::plus 并自己添加现在已删除的 typedef 以使 Boost 满意,但有更好的方法吗?
【问题讨论】:
-
注意:
std::make_pair应该在没有显式模板参数的情况下被调用,即std::make_pair(1, 2)
标签: c++ visual-studio-2019 c++03 c++20 boost-bind