From 196e363da2ec2fc958aa9e0d15505f46dc6d51df Mon Sep 17 00:00:00 2001 From: Andy Sawyer Date: Thu, 4 Sep 2014 21:07:50 +0100 Subject: [PATCH] Implement toString( std::pair ) - Transplanted the earlier implementation of StringMakerfrom ToStringPair.cpp to catch_tostring.h - Remove the specialisation of toString( pair ) from TrickyTests.cpp --- include/internal/catch_tostring.h | 15 +++++++++++++++ projects/SelfTest/ToStringPair.cpp | 18 ------------------ projects/SelfTest/TrickyTests.cpp | 12 ------------ 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index cf60547f..8cc02ad9 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -237,6 +237,20 @@ struct StringMaker> { }; #endif +template +struct StringMaker > { + static std::string convert( const std::pair& pair ) { + std::ostringstream oss; + oss << "{ " + << Catch::toString( pair.first ) + << ", " + << Catch::toString( pair.second ) + << " }"; + return oss.str(); + } +}; + + namespace Detail { template std::string makeString( T const& value ) { @@ -244,6 +258,7 @@ namespace Detail { } } // end namespace Detail + /// \brief converts any type to a string /// /// The default template forwards on to ostringstream - except when an diff --git a/projects/SelfTest/ToStringPair.cpp b/projects/SelfTest/ToStringPair.cpp index 2de4a55a..355cf1d1 100644 --- a/projects/SelfTest/ToStringPair.cpp +++ b/projects/SelfTest/ToStringPair.cpp @@ -1,23 +1,5 @@ #include "catch.hpp" -// === Pair === -namespace Catch { - // Note: If we put this in the right place in catch_tostring, then - // we can make it an overload of Catch::toString - template - struct StringMaker > { - static std::string convert( const std::pair& pair ) { - std::ostringstream oss; - oss << "{ " - << toString( pair.first ) - << ", " - << toString( pair.second ) - << " }"; - return oss.str(); - } - }; -} - TEST_CASE( "std::pair -> toString", "[toString][pair]" ) { std::pair value( 34, "xyzzy" ); diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index a1676570..74e473dd 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -17,18 +17,6 @@ #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" #endif -namespace Catch -{ - template<> - std::string toString >( const std::pair& value ) - { - std::ostringstream oss; - oss << "std::pair( " << value.first << ", " << value.second << " )"; - return oss.str(); - - } -} - /////////////////////////////////////////////////////////////////////////////// TEST_CASE (