proconlib

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

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: std::greater by key (tools/greater_by.hpp)

It compares two values by a given key selector.

Usage

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

License

Author

Constructor

tools::greater_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_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);
    }
  };
}


Back to top page