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:
Andy Sawyer 2014-09-04 21:07:50 +01:00
parent f559a51926
commit 196e363da2
3 changed files with 15 additions and 30 deletions

View File

@ -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

View File

@ -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" );

View File

@ -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
(