Publish toString support for pairs

Catch::toString support for pairs was implemented and tested
but not accessible from the include folder (thus in releases).
This commit is contained in:
mat tso 2016-03-07 22:12:39 +01:00
parent 88732e85b2
commit c3d80cf5eb
2 changed files with 13 additions and 17 deletions

View File

@ -186,6 +186,19 @@ std::string toString( std::vector<T,Allocator> const& v ) {
return Detail::rangeToString( v.begin(), v.end() ); return Detail::rangeToString( v.begin(), v.end() );
} }
// toString for pairs
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();
}
};
#ifdef CATCH_CONFIG_CPP11_TUPLE #ifdef CATCH_CONFIG_CPP11_TUPLE

View File

@ -1,23 +1,6 @@
#include "catch.hpp" #include "catch.hpp"
// === Pair === // === 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]" ) { TEST_CASE( "std::pair<int,std::string> -> toString", "[toString][pair]" ) {
std::pair<int,std::string> value( 34, "xyzzy" ); std::pair<int,std::string> value( 34, "xyzzy" );
REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" ); REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" );