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)