| 9407 | // user doesn't define PrintTo() for it. |
| 9408 | template <typename T> |
| 9409 | void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) { |
| 9410 | // With the following statement, during unqualified name lookup, |
| 9411 | // testing::internal2::operator<< appears as if it was declared in |
| 9412 | // the nearest enclosing namespace that contains both |
| 9413 | // ::testing_internal and ::testing::internal2, i.e. the global |
| 9414 | // namespace. For more details, refer to the C++ Standard section |
| 9415 | // 7.3.4-1 [namespace.udir]. This allows us to fall back onto |
| 9416 | // testing::internal2::operator<< in case T doesn't come with a << |
| 9417 | // operator. |
| 9418 | // |
| 9419 | // We cannot write 'using ::testing::internal2::operator<<;', which |
| 9420 | // gcc 3.3 fails to compile due to a compiler bug. |
| 9421 | using namespace ::testing::internal2; // NOLINT |
| 9422 | |
| 9423 | // Assuming T is defined in namespace foo, in the next statement, |
| 9424 | // the compiler will consider all of: |
| 9425 | // |
| 9426 | // 1. foo::operator<< (thanks to Koenig look-up), |
| 9427 | // 2. ::operator<< (as the current namespace is enclosed in ::), |
| 9428 | // 3. testing::internal2::operator<< (thanks to the using statement above). |
| 9429 | // |
| 9430 | // The operator<< whose type matches T best will be picked. |
| 9431 | // |
| 9432 | // We deliberately allow #2 to be a candidate, as sometimes it's |
| 9433 | // impossible to define #1 (e.g. when foo is ::std, defining |
| 9434 | // anything in it is undefined behavior unless you are a compiler |
| 9435 | // vendor.). |
| 9436 | *os << value; |
| 9437 | } |
| 9438 | |
| 9439 | } // namespace testing_internal |
| 9440 | |