Skip to content

Commit 5f4f38e

Browse files
dinordcopybara-github
authored andcommitted
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
1 parent 398e24a commit 5f4f38e

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

absl/log/internal/log_message.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,9 @@ class LogMessage {
183183
LogMessage& operator<<(char (&buf)[SIZE]) ABSL_ATTRIBUTE_NOINLINE;
184184

185185
// Types that support `AbslStringify()` are serialized that way.
186-
template <typename T,
187-
typename std::enable_if<absl::HasAbslStringify<T>::value,
188-
int>::type = 0>
189-
LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE;
190-
191186
// Types that don't support `AbslStringify()` but do support streaming into a
192187
// `std::ostream&` are serialized that way.
193-
template <typename T,
194-
typename std::enable_if<!absl::HasAbslStringify<T>::value,
195-
int>::type = 0>
188+
template <typename T>
196189
LogMessage& operator<<(const T& v) ABSL_ATTRIBUTE_NOINLINE;
197190

198191
// Note: We explicitly do not support `operator<<` for non-const references
@@ -308,21 +301,16 @@ class StringifySink final {
308301
};
309302

310303
// Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
311-
template <typename T,
312-
typename std::enable_if<absl::HasAbslStringify<T>::value, int>::type>
304+
template <typename T>
313305
LogMessage& LogMessage::operator<<(const T& v) {
314-
StringifySink sink(*this);
315-
// Replace with public API.
316-
AbslStringify(sink, v);
317-
return *this;
318-
}
319-
320-
// Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
321-
template <typename T,
322-
typename std::enable_if<!absl::HasAbslStringify<T>::value, int>::type>
323-
LogMessage& LogMessage::operator<<(const T& v) {
324-
OstreamView view(*data_);
325-
view.stream() << log_internal::NullGuard<T>().Guard(v);
306+
if constexpr (absl::HasAbslStringify<T>::value) {
307+
StringifySink sink(*this);
308+
// Replace with public API.
309+
AbslStringify(sink, v);
310+
} else {
311+
OstreamView view(*data_);
312+
view.stream() << log_internal::NullGuard<T>().Guard(v);
313+
}
326314
return *this;
327315
}
328316

0 commit comments

Comments
 (0)