mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-04 14:09:33 +01:00 
			
		
		
		
	Implement toString( std::pair<T1,T2> )
- Transplanted the earlier implementation of StringMaker<pair>from ToStringPair.cpp to catch_tostring.h - Remove the specialisation of toString( pair<int,int> ) from TrickyTests.cpp
This commit is contained in:
		@@ -237,6 +237,20 @@ struct StringMaker<std::tuple<Types...>> {
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
template<typename T1, typename T2>
 | 
			
		||||
struct StringMaker<std::pair<T1,T2> > {
 | 
			
		||||
    static std::string convert( const std::pair<T1,T2>& pair ) {
 | 
			
		||||
        std::ostringstream oss;
 | 
			
		||||
        oss << "{ "
 | 
			
		||||
            << Catch::toString( pair.first )
 | 
			
		||||
            << ", "
 | 
			
		||||
            << Catch::toString( pair.second )
 | 
			
		||||
            << " }";
 | 
			
		||||
        return oss.str();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace Detail {
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<typename T1, typename T2>
 | 
			
		||||
    struct StringMaker<std::pair<T1,T2> > {
 | 
			
		||||
        static std::string convert( const std::pair<T1,T2>& pair ) {
 | 
			
		||||
            std::ostringstream oss;
 | 
			
		||||
            oss << "{ "
 | 
			
		||||
                << toString( pair.first )
 | 
			
		||||
                << ", "
 | 
			
		||||
                << toString( pair.second )
 | 
			
		||||
                << " }";
 | 
			
		||||
            return oss.str();
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" )
 | 
			
		||||
{
 | 
			
		||||
    std::pair<int,std::string> value( 34, "xyzzy" );
 | 
			
		||||
 
 | 
			
		||||
@@ -17,18 +17,6 @@
 | 
			
		||||
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace Catch
 | 
			
		||||
{
 | 
			
		||||
    template<>
 | 
			
		||||
    std::string toString<std::pair<int, int> >( const std::pair<int, int>& value )
 | 
			
		||||
    {
 | 
			
		||||
        std::ostringstream oss;
 | 
			
		||||
        oss << "std::pair( " << value.first << ", " << value.second << " )";
 | 
			
		||||
        return oss.str();
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
TEST_CASE
 | 
			
		||||
(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user