mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 11:12:25 +01:00
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:
parent
88732e85b2
commit
c3d80cf5eb
@ -186,6 +186,19 @@ std::string toString( std::vector<T,Allocator> const& v ) {
|
||||
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
|
||||
|
||||
|
@ -1,23 +1,6 @@
|
||||
#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" );
|
||||
REQUIRE( Catch::toString( value ) == "{ 34, \"xyzzy\" }" );
|
||||
|
Loading…
Reference in New Issue
Block a user