Код: Выделить всё
std::binary_functionКод: Выделить всё
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());
Код: Выделить всё
inputПодробнее здесь: https://stackoverflow.com/questions/331 ... y-function
Мобильная версия