56
56
57
57
#include " gtest/internal/gtest-port.h"
58
58
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
+
59
66
GTEST_DISABLE_MSC_WARNINGS_PUSH_ (4251 \
60
67
/* class A needs to have dll-interface to be used by clients of class B */ )
61
68
@@ -111,8 +118,17 @@ class GTEST_API_ Message {
111
118
*ss_ << str;
112
119
}
113
120
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
+ >
116
132
inline Message& operator <<(const T& val) {
117
133
// Some libraries overload << for STL containers. These
118
134
// overloads are defined in the global namespace instead of ::std.
@@ -133,6 +149,22 @@ class GTEST_API_ Message {
133
149
return *this ;
134
150
}
135
151
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
+
136
168
// Streams a pointer value to this object.
137
169
//
138
170
// This function is an overload of the previous one. When you
0 commit comments