小编Lui*_*uis的帖子

替换binary_function

binary_function现在已弃用,将在C++ 17中删除.我搜索了不同的出版物,但我找不到更换它的确切方法.我想知道如何用C++ 11风格编写以下代码.

template <class T>
inline T absolute(const T &x) {
    return (x >= 0) ? x : -x;
}

template <class T>
struct absoluteLess : public std::binary_function<T, T, bool> {
    bool operator()(const T &x, const T &y) const {
        return absolute(x) < absolute(y);
    }
};

template <class T>
struct absoluteGreater : public std::binary_function<T, T, bool> {
    bool operator()(T &x, T &y) const {
        return absolute(x) > absolute(y);
    }
};
Run Code Online (Sandbox Code Playgroud)

编辑:我正在以下列方式使用这些功能:

output[j] = *std::max_element(input.begin() + prev, input.begin() + pos, …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

19
推荐指数
2
解决办法
4432
查看次数

标签 统计

c++ ×1

c++11 ×1