5656
5757#include " gtest/internal/gtest-port.h"
5858
59+ #ifdef GTEST_HAS_ABSL
60+ #include < type_traits>
61+
62+ #include " absl/strings/internal/has_absl_stringify.h"
63+ #include " absl/strings/str_cat.h"
64+ #endif // GTEST_HAS_ABSL
65+
5966GTEST_DISABLE_MSC_WARNINGS_PUSH_ (4251 \
6067/* class A needs to have dll-interface to be used by clients of class B */ )
6168
@@ -111,8 +118,17 @@ class GTEST_API_ Message {
111118 *ss_ << str;
112119 }
113120
114- // Streams a non-pointer value to this object.
115- template <typename T>
121+ // Streams a non-pointer value to this object. If building a version of
122+ // GoogleTest with ABSL, this overload is only enabled if the value does not
123+ // have an AbslStringify definition.
124+ template <typename T
125+ #ifdef GTEST_HAS_ABSL
126+ ,
127+ typename std::enable_if<
128+ !absl::strings_internal::HasAbslStringify<T>::value, // NOLINT
129+ int >::type = 0
130+ #endif // GTEST_HAS_ABSL
131+ >
116132 inline Message& operator <<(const T& val) {
117133 // Some libraries overload << for STL containers. These
118134 // overloads are defined in the global namespace instead of ::std.
@@ -133,6 +149,22 @@ class GTEST_API_ Message {
133149 return *this ;
134150 }
135151
152+ #ifdef GTEST_HAS_ABSL
153+ // Streams a non-pointer value with an AbslStringify definition to this
154+ // object.
155+ template <typename T,
156+ typename std::enable_if<
157+ absl::strings_internal::HasAbslStringify<T>::value, // NOLINT
158+ int >::type = 0 >
159+ inline Message& operator <<(const T& val) {
160+ // ::operator<< is needed here for a similar reason as with the non-Abseil
161+ // version above
162+ using ::operator <<;
163+ *ss_ << absl::StrCat (val);
164+ return *this ;
165+ }
166+ #endif // GTEST_HAS_ABSL
167+
136168 // Streams a pointer value to this object.
137169 //
138170 // This function is an overload of the previous one. When you
0 commit comments