std::binary_function
is deprecated now and is going to be deleted in c++17. I searched on different publications, but I couldn't find a exact way to replace it. I'd like to know how should I write the following code in c++11 style.
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);
}
};
EDIT
I'm using the functions in the following way:
output[j] = *std::max_element(input.begin() + prev,
input.begin() + pos,
absoluteLess<float>());
input
and output
are std::vector
s, inside a for-loop.