Замена std::binary_functionC++

Программы на C++. Форум разработчиков
Anonymous
Замена std::binary_function

Сообщение Anonymous »

Код: Выделить всё

std::binary_function
устарел и будет удален в c++17. Я искал в разных публикациях, но точного способа замены не нашел. Я хотел бы знать, как мне написать следующий код в стиле c++11.

Код: Выделить всё

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

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

template 
struct absoluteGreater : public std::binary_function {
bool operator()(T &x, T &y) const {
return absolute(x) > absolute(y);
}
};
РЕДАКТИРОВАТЬ
Я использую функции следующим образом:

Код: Выделить всё

output[j] = *std::max_element(input.begin() + prev,
input.begin() + pos,
absoluteLess());
и вывод — это std::vector внутри цикла for.


Подробнее здесь: https://stackoverflow.com/questions/331 ... y-function

Вернуться в «C++»