proconlib

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

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: chmax function (tools/chmax.hpp)

template <typename M, typename N>
bool chmax(M& lhs, N rhs);

It runs lhs = std::max(lhs, rhs);. It returns true if lhs has been updated. Otherwise, it returns false.

Constraints

Time Complexity

License

Author

Required by

Verified with

Code

#ifndef TOOLS_CHMAX_HPP
#define TOOLS_CHMAX_HPP

#include <type_traits>
#include <utility>

namespace tools {

  template <typename M, typename N>
  bool chmax(M& lhs, const N& rhs) {
    bool updated;
    if constexpr (::std::is_integral_v<M> && ::std::is_integral_v<N>) {
      updated = ::std::cmp_less(lhs, rhs);
    } else {
      updated = lhs < rhs;
    }
    if (updated) lhs = rhs;
    return updated;
  }
}

#endif
#line 1 "tools/chmax.hpp"



#include <type_traits>
#include <utility>

namespace tools {

  template <typename M, typename N>
  bool chmax(M& lhs, const N& rhs) {
    bool updated;
    if constexpr (::std::is_integral_v<M> && ::std::is_integral_v<N>) {
      updated = ::std::cmp_less(lhs, rhs);
    } else {
      updated = lhs < rhs;
    }
    if (updated) lhs = rhs;
    return updated;
  }
}


Back to top page