From c97f2f560bc6893b0b535b4312a161917c07854b Mon Sep 17 00:00:00 2001 From: shiqian Date: Thu, 11 Dec 2008 17:22:59 +0000 Subject: [PATCH] Fixes compatibility with gcc 4.3's tuple implementation. --- include/gmock/gmock-printers.h | 82 ++++++++++++++++++++++++++++++---- test/gmock-printers_test.cc | 23 ++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) diff --git a/include/gmock/gmock-printers.h b/include/gmock/gmock-printers.h index 628fc744..eae6e52d 100644 --- a/include/gmock/gmock-printers.h +++ b/include/gmock/gmock-printers.h @@ -365,19 +365,85 @@ struct TuplePrefixPrinter<1> { } }; -// We support tuples of up-to 10 fields. Note that an N-tuple type is -// just an (N + 1)-tuple type where the last field has a special, -// unused type. +// Helper function for printing a tuple. T must be instantiated with +// a tuple type. +template +void PrintTupleTo(const T& t, ::std::ostream* os) { + *os << "("; + TuplePrefixPrinter< ::std::tr1::tuple_size::value>:: + PrintPrefixTo(t, os); + *os << ")"; +} + +// Overloaded PrintTo() for tuples of various arities. We support +// tuples of up-to 10 fields. The following implementation works +// regardless of whether tr1::tuple is implemented using the +// non-standard variadic template feature or not. + +inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + template void PrintTo( const ::std::tr1::tuple& t, ::std::ostream* os) { - typedef ::std::tr1::tuple Tuple; - *os << "("; - TuplePrefixPrinter< ::std::tr1::tuple_size::value>:: - PrintPrefixTo(t, os); - *os << ")"; + PrintTupleTo(t, os); } // Overload for std::pair. diff --git a/test/gmock-printers_test.cc b/test/gmock-printers_test.cc index 7457af2b..9677491a 100644 --- a/test/gmock-printers_test.cc +++ b/test/gmock-printers_test.cc @@ -754,6 +754,29 @@ TEST(PrintTupleTest, VariousSizes) { tuple t2('a', true); EXPECT_EQ("('a' (97), true)", Print(t2)); + tuple t3(false, 2, 3); + EXPECT_EQ("(false, 2, 3)", Print(t3)); + + tuple t4(false, 2, 3, 4); + EXPECT_EQ("(false, 2, 3, 4)", Print(t4)); + + tuple t5(false, 2, 3, 4, true); + EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5)); + + tuple t6(false, 2, 3, 4, true, 6); + EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6)); + + tuple t7(false, 2, 3, 4, true, 6, 7); + EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7)); + + tuple t8( + false, 2, 3, 4, true, 6, 7, true); + EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8)); + + tuple t9( + false, 2, 3, 4, true, 6, 7, true, 9); + EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9)); + const char* const str = "8"; tuple