This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "tools/greater_by.hpp"
It compares two values by a given key selector.
std::sort(a.begin(), a.end(), tools::greater_by([](int a_i) { return std::abs(x); }));
tools::greater_by<F> comp(F f);
It creates a comparator.
template <typename T>
bool comp(T x, T y);
It returns true
if f(x) > f(y)
.
Otherwise, it returns false
.
f
has operator()(T x)
f(x)
is comparablef(x)
takes constant time#ifndef TOOLS_GREATER_BY_HPP
#define TOOLS_GREATER_BY_HPP
namespace tools {
template <class F>
class greater_by {
private:
F selector;
public:
greater_by(const F& selector) : selector(selector) {
}
template <class T>
bool operator()(const T& x, const T& y) const {
return selector(x) > selector(y);
}
};
}
#endif
#line 1 "tools/greater_by.hpp"
namespace tools {
template <class F>
class greater_by {
private:
F selector;
public:
greater_by(const F& selector) : selector(selector) {
}
template <class T>
bool operator()(const T& x, const T& y) const {
return selector(x) > selector(y);
}
};
}