小编Mad*_*ter的帖子

Boost 绑定和 'result_type':不是成员,c++03 友好

Visual Studio 2019 的最新 16.6 更新删除了std::plus::result_typestd::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; …
Run Code Online (Sandbox Code Playgroud)

c++ boost-bind c++03 c++20 visual-studio-2019

5
推荐指数
1
解决办法
763
查看次数

标签 统计

boost-bind ×1

c++ ×1

c++03 ×1

c++20 ×1

visual-studio-2019 ×1