This documentation is automatically generated by competitive-verifier/competitive-verifier
#include "tools/less_by.hpp"
It compares two values by a given key selector.
std::sort(a.begin(), a.end(), tools::less_by([](int a_i) { return std::abs(x); }));
tools::less_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_LESS_BY_HPP
#define TOOLS_LESS_BY_HPP
namespace tools {
template <class F>
class less_by {
private:
F selector;
public:
less_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/less_by.hpp"
namespace tools {
template <class F>
class less_by {
private:
F selector;
public:
less_by(const F& selector) : selector(selector) {
}
template <class T>
bool operator()(const T& x, const T& y) const {
return selector(x) < selector(y);
}
};
}