diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index ff9248cdce..72b7229473 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -280,6 +280,7 @@ rtc_source_set("logging") { ":platform_thread_types", ":stringutils", ":timeutils", + "//third_party/abseil-cpp/absl/meta:type_traits", "//third_party/abseil-cpp/absl/strings", ] @@ -342,6 +343,7 @@ rtc_source_set("checks") { deps = [ ":safe_compare", "system:inline", + "//third_party/abseil-cpp/absl/meta:type_traits", "//third_party/abseil-cpp/absl/strings", ] if (is_android) { diff --git a/rtc_base/checks.h b/rtc_base/checks.h index dbdc004433..3bfa75973f 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -42,6 +42,7 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg); #include +#include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" #include "rtc_base/numerics/safe_compare.h" #include "rtc_base/system/inline.h" @@ -178,20 +179,15 @@ inline Val MakeVal(const void* x) { } // The enum class types are not implicitly convertible to arithmetic types. -template < - typename T, - typename std::enable_if::value && - !std::is_arithmetic::value>::type* = nullptr> -inline decltype(MakeVal(std::declval::type>())) -MakeVal(T x) { - return {static_cast::type>(x)}; +template ::value && + !std::is_arithmetic::value>* = nullptr> +inline decltype(MakeVal(std::declval>())) MakeVal( + T x) { + return {static_cast>(x)}; } -template ::type, - typename T2 = decltype(ToLogString(std::declval())), - typename std::enable_if::value>::type* = - nullptr> +template ()))* = nullptr> ToStringVal MakeVal(const T& x) { return {ToLogString(x)}; } @@ -205,21 +201,19 @@ template <> class LogStreamer<> final { public: template ::value || - std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer()))> operator<<( - U arg) const { - return LogStreamer()))>(MakeVal(arg), - this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value || + std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { + return LogStreamer(MakeVal(arg), this); } template ::value && - !std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer()))> operator<<( - const U& arg) const { - return LogStreamer()))>(MakeVal(arg), - this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value && + !std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { + return LogStreamer(MakeVal(arg), this); } template @@ -251,21 +245,19 @@ class LogStreamer final { : arg_(arg), prior_(prior) {} template ::value || - std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer())), T, Ts...> - operator<<(U arg) const { - return LogStreamer())), T, Ts...>( - MakeVal(arg), this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value || + std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { + return LogStreamer(MakeVal(arg), this); } template ::value && - !std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer())), T, Ts...> - operator<<(const U& arg) const { - return LogStreamer())), T, Ts...>( - MakeVal(arg), this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value && + !std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { + return LogStreamer(MakeVal(arg), this); } template diff --git a/rtc_base/logging.h b/rtc_base/logging.h index 362aeae73c..5d94308907 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -51,6 +51,7 @@ #include #include +#include "absl/meta/type_traits.h" #include "absl/strings/string_view.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/deprecation.h" @@ -248,13 +249,12 @@ inline Val MakeVal( } // The enum class types are not implicitly convertible to arithmetic types. -template < - typename T, - typename std::enable_if::value && - !std::is_arithmetic::value>::type* = nullptr> -inline decltype(MakeVal(std::declval::type>())) -MakeVal(T x) { - return {static_cast::type>(x)}; +template ::value && + !std::is_arithmetic::value>* = nullptr> +inline decltype(MakeVal(std::declval>())) MakeVal( + T x) { + return {static_cast>(x)}; } #ifdef WEBRTC_ANDROID @@ -264,14 +264,10 @@ inline Val MakeVal( } #endif -template +template struct has_to_log_string : std::false_type {}; template -struct has_to_log_string< - T, - typename std::enable_if< - std::is_same()))>::value>::type> +struct has_to_log_string()))> : std::true_type {}; // Handle arbitrary types other than the above by falling back to stringstream. @@ -279,26 +275,22 @@ struct has_to_log_string< // it anymore. No in-tree caller does, but some external callers still do. template < typename T, - typename T1 = typename std::decay::type, - typename std::enable_if< - std::is_class::value && !std::is_same::value && - !std::is_same::value && - !has_to_log_string::value && + typename T1 = absl::decay_t, + absl::enable_if_t::value && + !std::is_same::value && + !std::is_same::value && + !has_to_log_string::value && #ifdef WEBRTC_ANDROID - !std::is_same::value && + !std::is_same::value && #endif - !std::is_same::value>::type* = nullptr> + !std::is_same::value>* = nullptr> ToStringVal MakeVal(const T& x) { std::ostringstream os; // no-presubmit-check TODO(webrtc:8982) os << x; return {os.str()}; } -template < - typename T, - typename T1 = typename std::decay::type, - typename std::enable_if::value && - has_to_log_string::value>::type* = nullptr> +template ::value>* = nullptr> ToStringVal MakeVal(const T& x) { return {ToLogString(x)}; } @@ -314,21 +306,19 @@ template <> class LogStreamer<> final { public: template ::value || - std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer()))> operator<<( - U arg) const { - return LogStreamer()))>(MakeVal(arg), - this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value || + std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { + return LogStreamer(MakeVal(arg), this); } template ::value && - !std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer()))> operator<<( - const U& arg) const { - return LogStreamer()))>(MakeVal(arg), - this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value && + !std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { + return LogStreamer(MakeVal(arg), this); } template @@ -347,21 +337,19 @@ class LogStreamer final { : arg_(arg), prior_(prior) {} template ::value || - std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer())), T, Ts...> - operator<<(U arg) const { - return LogStreamer())), T, Ts...>( - MakeVal(arg), this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value || + std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(U arg) const { + return LogStreamer(MakeVal(arg), this); } template ::value && - !std::is_enum::value>::type* = nullptr> - RTC_FORCE_INLINE LogStreamer())), T, Ts...> - operator<<(const U& arg) const { - return LogStreamer())), T, Ts...>( - MakeVal(arg), this); + typename V = decltype(MakeVal(std::declval())), + absl::enable_if_t::value && + !std::is_enum::value>* = nullptr> + RTC_FORCE_INLINE LogStreamer operator<<(const U& arg) const { + return LogStreamer(MakeVal(arg), this); } template