| Index: webrtc/base/safe_compare.h
|
| diff --git a/webrtc/base/safe_compare.h b/webrtc/base/safe_compare.h
|
| index 39fb917a700862312c823bf12febb3dbc0fdf1b7..494a0c14043a20845dc8818615d7088969bfd9e7 100644
|
| --- a/webrtc/base/safe_compare.h
|
| +++ b/webrtc/base/safe_compare.h
|
| @@ -37,6 +37,8 @@
|
| #include <type_traits>
|
| #include <utility>
|
|
|
| +#include "webrtc/base/type_traits.h"
|
| +
|
| namespace rtc {
|
| namespace safe_cmp {
|
|
|
| @@ -145,81 +147,21 @@ RTC_SAFECMP_MAKE_OP(GtOp, >)
|
| RTC_SAFECMP_MAKE_OP(GeOp, >=)
|
| #undef RTC_SAFECMP_MAKE_OP
|
|
|
| -// Determines if the given type is an enum that converts implicitly to
|
| -// an integral type.
|
| -template <typename T>
|
| -struct IsIntEnum {
|
| - private:
|
| - // This overload is used if the type is an enum, and unary plus
|
| - // compiles and turns it into an integral type.
|
| - template <typename X,
|
| - typename std::enable_if<
|
| - std::is_enum<X>::value &&
|
| - std::is_integral<decltype(+std::declval<X>())>::value>::type* =
|
| - nullptr>
|
| - static int Test(int);
|
| -
|
| - // Otherwise, this overload is used.
|
| - template <typename>
|
| - static char Test(...);
|
| -
|
| - public:
|
| - static constexpr bool value =
|
| - std::is_same<decltype(Test<typename std::remove_reference<T>::type>(0)),
|
| - int>::value;
|
| -};
|
| -
|
| -// Determines if the given type is integral, or an enum that
|
| -// converts implicitly to an integral type.
|
| -template <typename T>
|
| -struct IsIntlike {
|
| - private:
|
| - using X = typename std::remove_reference<T>::type;
|
| -
|
| - public:
|
| - static constexpr bool value =
|
| - std::is_integral<X>::value || IsIntEnum<X>::value;
|
| -};
|
| -
|
| -namespace test_enum_intlike {
|
| -
|
| -enum E1 { e1 };
|
| -enum { e2 };
|
| -enum class E3 { e3 };
|
| -struct S {};
|
| -
|
| -static_assert(IsIntEnum<E1>::value, "");
|
| -static_assert(IsIntEnum<decltype(e2)>::value, "");
|
| -static_assert(!IsIntEnum<E3>::value, "");
|
| -static_assert(!IsIntEnum<int>::value, "");
|
| -static_assert(!IsIntEnum<float>::value, "");
|
| -static_assert(!IsIntEnum<S>::value, "");
|
| -
|
| -static_assert(IsIntlike<E1>::value, "");
|
| -static_assert(IsIntlike<decltype(e2)>::value, "");
|
| -static_assert(!IsIntlike<E3>::value, "");
|
| -static_assert(IsIntlike<int>::value, "");
|
| -static_assert(!IsIntlike<float>::value, "");
|
| -static_assert(!IsIntlike<S>::value, "");
|
| -
|
| -} // test_enum_intlike
|
| } // namespace safe_cmp_impl
|
|
|
| -#define RTC_SAFECMP_MAKE_FUN(name) \
|
| - template <typename T1, typename T2, \
|
| - typename std::enable_if< \
|
| - safe_cmp_impl::IsIntlike<T1>::value && \
|
| - safe_cmp_impl::IsIntlike<T2>::value>::type* = nullptr> \
|
| - inline bool name(T1 a, T2 b) { \
|
| - /* Unary plus here turns enums into real integral types. */ \
|
| - return safe_cmp_impl::Cmp<safe_cmp_impl::name##Op>(+a, +b); \
|
| - } \
|
| - template <typename T1, typename T2, \
|
| - typename std::enable_if< \
|
| - !safe_cmp_impl::IsIntlike<T1>::value || \
|
| - !safe_cmp_impl::IsIntlike<T2>::value>::type* = nullptr> \
|
| - inline bool name(T1&& a, T2&& b) { \
|
| - return safe_cmp_impl::name##Op::Op(a, b); \
|
| +#define RTC_SAFECMP_MAKE_FUN(name) \
|
| + template <typename T1, typename T2, \
|
| + typename std::enable_if<IsIntlike<T1>::value && \
|
| + IsIntlike<T2>::value>::type* = nullptr> \
|
| + inline bool name(T1 a, T2 b) { \
|
| + /* Unary plus here turns enums into real integral types. */ \
|
| + return safe_cmp_impl::Cmp<safe_cmp_impl::name##Op>(+a, +b); \
|
| + } \
|
| + template <typename T1, typename T2, \
|
| + typename std::enable_if<!IsIntlike<T1>::value || \
|
| + !IsIntlike<T2>::value>::type* = nullptr> \
|
| + inline bool name(T1&& a, T2&& b) { \
|
| + return safe_cmp_impl::name##Op::Op(a, b); \
|
| }
|
| RTC_SAFECMP_MAKE_FUN(Eq)
|
| RTC_SAFECMP_MAKE_FUN(Ne)
|
|
|