#ifndef RTC_BASE_NUMERICS_SAFE_COMPARE_H_
#define RTC_BASE_NUMERICS_SAFE_COMPARE_H_
#include <stddef.h>
#include <stdint.h>
#include <type_traits>
#include "rtc_base/type_traits.h"
namespace rtc {
namespace safe_cmp_impl {
template <size_t N>
struct LargerIntImpl : std::false_type { … };
template <>
struct LargerIntImpl<sizeof(int8_t)> : std::true_type { … };
template <>
struct LargerIntImpl<sizeof(int16_t)> : std::true_type { … };
template <>
struct LargerIntImpl<sizeof(int32_t)> : std::true_type { … };
template <typename T1, typename T2>
struct LargerInt
: LargerIntImpl<sizeof(T1) < sizeof(T2) || sizeof(T1) < sizeof(int*)
? sizeof(T1)
: 0> { … };
template <typename T>
constexpr typename std::make_unsigned<T>::type MakeUnsigned(T a) { … }
template <typename Op,
typename T1,
typename T2,
typename std::enable_if<std::is_signed<T1>::value ==
std::is_signed<T2>::value>::type* = nullptr>
constexpr bool Cmp(T1 a, T2 b) { … }
template <typename Op,
typename T1,
typename T2,
typename std::enable_if<std::is_signed<T1>::value &&
std::is_unsigned<T2>::value &&
LargerInt<T2, T1>::value>::type* = nullptr>
constexpr bool Cmp(T1 a, T2 b) { … }
template <typename Op,
typename T1,
typename T2,
typename std::enable_if<std::is_unsigned<T1>::value &&
std::is_signed<T2>::value &&
LargerInt<T1, T2>::value>::type* = nullptr>
constexpr bool Cmp(T1 a, T2 b) { … }
template <typename Op,
typename T1,
typename T2,
typename std::enable_if<std::is_signed<T1>::value &&
std::is_unsigned<T2>::value &&
!LargerInt<T2, T1>::value>::type* = nullptr>
constexpr bool Cmp(T1 a, T2 b) { … }
template <typename Op,
typename T1,
typename T2,
typename std::enable_if<std::is_unsigned<T1>::value &&
std::is_signed<T2>::value &&
!LargerInt<T1, T2>::value>::type* = nullptr>
constexpr bool Cmp(T1 a, T2 b) { … }
#define RTC_SAFECMP_MAKE_OP …
RTC_SAFECMP_MAKE_OP(EqOp, ==)
RTC_SAFECMP_MAKE_OP(NeOp, !=)
RTC_SAFECMP_MAKE_OP(LtOp, <)
RTC_SAFECMP_MAKE_OP
RTC_SAFECMP_MAKE_OP
RTC_SAFECMP_MAKE_OP
#undef RTC_SAFECMP_MAKE_OP
}
#define RTC_SAFECMP_MAKE_FUN …
RTC_SAFECMP_MAKE_FUN
RTC_SAFECMP_MAKE_FUN
RTC_SAFECMP_MAKE_FUN
RTC_SAFECMP_MAKE_FUN
RTC_SAFECMP_MAKE_FUN
RTC_SAFECMP_MAKE_FUN
#undef RTC_SAFECMP_MAKE_FUN
}
#endif