proconlib

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: std::less by key (tools/less_by.hpp)

It compares two values by a given key selector.

Usage

std::sort(a.begin(), a.end(), tools::less_by([](int a_i) { return std::abs(x); }));

License

Author

Constructor

tools::less_by<F> comp(F f);

It creates a comparator.

Constraints

Time Complexity

operator()

template <typename T>
bool comp(T x, T y);

It returns true if f(x) < f(y). Otherwise, it returns false.

Constraints

Time Complexity

Required by

Verified with

Code

#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);
    }
  };
}


Back to top page