proxygen
testing_internal Namespace Reference

Functions

template<typename T >
void DefaultPrintNonContainerTo (const T &value,::std::ostream *os)
 

Function Documentation

template<typename T >
void testing_internal::DefaultPrintNonContainerTo ( const T value,
::std::ostream *  os 
)

Definition at line 222 of file gtest-printers.h.

References value.

Referenced by testing::internal::DefaultPrintTo(), and testing::internal2::TypeWithoutFormatter< T, kConvertibleToInteger >::PrintValue().

222  {
223  // With the following statement, during unqualified name lookup,
224  // testing::internal2::operator<< appears as if it was declared in
225  // the nearest enclosing namespace that contains both
226  // ::testing_internal and ::testing::internal2, i.e. the global
227  // namespace. For more details, refer to the C++ Standard section
228  // 7.3.4-1 [namespace.udir]. This allows us to fall back onto
229  // testing::internal2::operator<< in case T doesn't come with a <<
230  // operator.
231  //
232  // We cannot write 'using ::testing::internal2::operator<<;', which
233  // gcc 3.3 fails to compile due to a compiler bug.
234  using namespace ::testing::internal2; // NOLINT
235 
236  // Assuming T is defined in namespace foo, in the next statement,
237  // the compiler will consider all of:
238  //
239  // 1. foo::operator<< (thanks to Koenig look-up),
240  // 2. ::operator<< (as the current namespace is enclosed in ::),
241  // 3. testing::internal2::operator<< (thanks to the using statement above).
242  //
243  // The operator<< whose type matches T best will be picked.
244  //
245  // We deliberately allow #2 to be a candidate, as sometimes it's
246  // impossible to define #1 (e.g. when foo is ::std, defining
247  // anything in it is undefined behavior unless you are a compiler
248  // vendor.).
249  *os << value;
250 }
static const char *const value
Definition: Conv.cpp:50