Using absl traits for checks and logging.
Bug: webrtc:9883 Change-Id: If4af810c1ba64c6c022c0fb5328a75527bec5934 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133622 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27993}
This commit is contained in:

committed by
Commit Bot

parent
1ff16c87aa
commit
f4e085a499
@ -42,6 +42,7 @@ RTC_NORETURN void rtc_FatalMessage(const char* file, int line, const char* msg);
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<CheckArgType::kVoidP, const void*> MakeVal(const void* x) {
|
||||
}
|
||||
|
||||
// The enum class types are not implicitly convertible to arithmetic types.
|
||||
template <
|
||||
typename T,
|
||||
typename std::enable_if<std::is_enum<T>::value &&
|
||||
!std::is_arithmetic<T>::value>::type* = nullptr>
|
||||
inline decltype(MakeVal(std::declval<typename std::underlying_type<T>::type>()))
|
||||
MakeVal(T x) {
|
||||
return {static_cast<typename std::underlying_type<T>::type>(x)};
|
||||
template <typename T,
|
||||
absl::enable_if_t<std::is_enum<T>::value &&
|
||||
!std::is_arithmetic<T>::value>* = nullptr>
|
||||
inline decltype(MakeVal(std::declval<absl::underlying_type_t<T>>())) MakeVal(
|
||||
T x) {
|
||||
return {static_cast<absl::underlying_type_t<T>>(x)};
|
||||
}
|
||||
|
||||
template <typename T,
|
||||
typename T1 = typename std::decay<T>::type,
|
||||
typename T2 = decltype(ToLogString(std::declval<T>())),
|
||||
typename std::enable_if<std::is_same<T2, std::string>::value>::type* =
|
||||
nullptr>
|
||||
template <typename T, decltype(ToLogString(std::declval<T>()))* = nullptr>
|
||||
ToStringVal MakeVal(const T& x) {
|
||||
return {ToLogString(x)};
|
||||
}
|
||||
@ -205,21 +201,19 @@ template <>
|
||||
class LogStreamer<> final {
|
||||
public:
|
||||
template <typename U,
|
||||
typename std::enable_if<std::is_arithmetic<U>::value ||
|
||||
std::is_enum<U>::value>::type* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>()))> operator<<(
|
||||
U arg) const {
|
||||
return LogStreamer<decltype(MakeVal(std::declval<U>()))>(MakeVal(arg),
|
||||
this);
|
||||
typename V = decltype(MakeVal(std::declval<U>())),
|
||||
absl::enable_if_t<std::is_arithmetic<U>::value ||
|
||||
std::is_enum<U>::value>* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<V> operator<<(U arg) const {
|
||||
return LogStreamer<V>(MakeVal(arg), this);
|
||||
}
|
||||
|
||||
template <typename U,
|
||||
typename std::enable_if<!std::is_arithmetic<U>::value &&
|
||||
!std::is_enum<U>::value>::type* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>()))> operator<<(
|
||||
const U& arg) const {
|
||||
return LogStreamer<decltype(MakeVal(std::declval<U>()))>(MakeVal(arg),
|
||||
this);
|
||||
typename V = decltype(MakeVal(std::declval<U>())),
|
||||
absl::enable_if_t<!std::is_arithmetic<U>::value &&
|
||||
!std::is_enum<U>::value>* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<V> operator<<(const U& arg) const {
|
||||
return LogStreamer<V>(MakeVal(arg), this);
|
||||
}
|
||||
|
||||
template <typename... Us>
|
||||
@ -251,21 +245,19 @@ class LogStreamer<T, Ts...> final {
|
||||
: arg_(arg), prior_(prior) {}
|
||||
|
||||
template <typename U,
|
||||
typename std::enable_if<std::is_arithmetic<U>::value ||
|
||||
std::is_enum<U>::value>::type* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>
|
||||
operator<<(U arg) const {
|
||||
return LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>(
|
||||
MakeVal(arg), this);
|
||||
typename V = decltype(MakeVal(std::declval<U>())),
|
||||
absl::enable_if_t<std::is_arithmetic<U>::value ||
|
||||
std::is_enum<U>::value>* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(U arg) const {
|
||||
return LogStreamer<V, T, Ts...>(MakeVal(arg), this);
|
||||
}
|
||||
|
||||
template <typename U,
|
||||
typename std::enable_if<!std::is_arithmetic<U>::value &&
|
||||
!std::is_enum<U>::value>::type* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>
|
||||
operator<<(const U& arg) const {
|
||||
return LogStreamer<decltype(MakeVal(std::declval<U>())), T, Ts...>(
|
||||
MakeVal(arg), this);
|
||||
typename V = decltype(MakeVal(std::declval<U>())),
|
||||
absl::enable_if_t<!std::is_arithmetic<U>::value &&
|
||||
!std::is_enum<U>::value>* = nullptr>
|
||||
RTC_FORCE_INLINE LogStreamer<V, T, Ts...> operator<<(const U& arg) const {
|
||||
return LogStreamer<V, T, Ts...>(MakeVal(arg), this);
|
||||
}
|
||||
|
||||
template <typename... Us>
|
||||
|
Reference in New Issue
Block a user