std::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);
}
};
РЕДАКТИРОВАТЬ
Я использую функции следующим образом:
output[j] = *std::max_element(input.begin() + prev,
input.begin() + pos,
absoluteLess<float>());
input
и output
- это std::vector
внутри цикла for.
operator()
без необходимостиbinary_function
- person Bryan Chen   schedule 14.10.2015binary_function
в конце 2020 г. github. com/llvm/llvm-project/blob/main/libcxx/include/ Более того,clang++ --std=c++17
по-прежнему можно компилировать код, который используетbinary_function
github.com/llvm/llvm-project/blob/main/libcxx/include/ - person x4444   schedule 29.12.2020