`internal/log_message`: Use `if constexpr` instead of SFINAE for `operator<<` SFINAE is harder to read and it makes mangled names longer. PiperOrigin-RevId: 729591470 Change-Id: I8d254fdd02b993580c7a4df8f477ef4fa11b6f76
diff --git a/absl/log/internal/log_message.h b/absl/log/internal/log_message.h index 7d0e403..4986e7e 100644 --- a/absl/log/internal/log_message.h +++ b/absl/log/internal/log_message.h
@@ -183,16 +183,9 @@ LogMessage& operator<<(char (&buf)[SIZE]) ABSL_ATTRIBUTE_NOINLINE; // Types that support `AbslStringify()` are serialized that way. - template <typename T, - typename std::enable_if<absl::HasAbslStringify<T>::value, - int>::type = 0> - LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE; - // Types that don't support `AbslStringify()` but do support streaming into a // `std::ostream&` are serialized that way. - template <typename T, - typename std::enable_if<!absl::HasAbslStringify<T>::value, - int>::type = 0> + template <typename T> LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE; // Note: We explicitly do not support `operator<<` for non-const references @@ -308,21 +301,16 @@ }; // Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE` -template <typename T, - typename std::enable_if<absl::HasAbslStringify<T>::value, int>::type> +template <typename T> LogMessage& LogMessage::operator<<(const T& v) { - StringifySink sink(*this); - // Replace with public API. - AbslStringify(sink, v); - return *this; -} - -// Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE` -template <typename T, - typename std::enable_if<!absl::HasAbslStringify<T>::value, int>::type> -LogMessage& LogMessage::operator<<(const T& v) { - OstreamView view(*data_); - view.stream() << log_internal::NullGuard<T>().Guard(v); + if constexpr (absl::HasAbslStringify<T>::value) { + StringifySink sink(*this); + // Replace with public API. + AbslStringify(sink, v); + } else { + OstreamView view(*data_); + view.stream() << log_internal::NullGuard<T>().Guard(v); + } return *this; }