proconlib

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

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: std::cmp_less extended for my library (tools/cmp_less.hpp)

template <tools::integral T, tools::integral U>
constexpr bool cmp_less(T t, U u) noexcept;

It is almost identical to std::cmp_less, but compatible with user-defined extended integral types.

Constraints

Time Complexity

License

Author

Depends on

Required by

Verified with

Code

#ifndef TOOLS_CMP_LESS_HPP
#define TOOLS_CMP_LESS_HPP

#include "tools/integral.hpp"
#include "tools/is_signed.hpp"
#include "tools/make_unsigned.hpp"

namespace tools {
  template <tools::integral T, tools::integral U>
  constexpr bool cmp_less(const T t, const U u) noexcept {
    using UT = tools::make_unsigned_t<T>;
    using UU = tools::make_unsigned_t<U>;
    if constexpr (tools::is_signed_v<T> == tools::is_signed_v<U>) {
      return t < u;
    } else if constexpr (tools::is_signed_v<T>) {
      return t < 0 ? true : static_cast<UT>(t) < u;
    } else {
      return u < 0 ? false : t < static_cast<UU>(u);
    }
  }
}

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



#line 1 "tools/integral.hpp"



#line 1 "tools/is_integral.hpp"



#include <type_traits>

namespace tools {
  template <typename T>
  struct is_integral : std::is_integral<T> {};

  template <typename T>
  inline constexpr bool is_integral_v = tools::is_integral<T>::value;
}


#line 5 "tools/integral.hpp"

namespace tools {
  template <typename T>
  concept integral = tools::is_integral_v<T>;
}


#line 1 "tools/is_signed.hpp"



#line 5 "tools/is_signed.hpp"

namespace tools {
  template <typename T>
  struct is_signed : std::is_signed<T> {};

  template <typename T>
  inline constexpr bool is_signed_v = tools::is_signed<T>::value;
}


#line 1 "tools/make_unsigned.hpp"



#line 5 "tools/make_unsigned.hpp"

namespace tools {
  template <typename T>
  struct make_unsigned : std::make_unsigned<T> {};

  template <typename T>
  using make_unsigned_t = typename tools::make_unsigned<T>::type;
}


#line 7 "tools/cmp_less.hpp"

namespace tools {
  template <tools::integral T, tools::integral U>
  constexpr bool cmp_less(const T t, const U u) noexcept {
    using UT = tools::make_unsigned_t<T>;
    using UU = tools::make_unsigned_t<U>;
    if constexpr (tools::is_signed_v<T> == tools::is_signed_v<U>) {
      return t < u;
    } else if constexpr (tools::is_signed_v<T>) {
      return t < 0 ? true : static_cast<UT>(t) < u;
    } else {
      return u < 0 ? false : t < static_cast<UU>(u);
    }
  }
}


Back to top page