mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 03:02:24 +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:
parent
f559a51926
commit
196e363da2
@ -237,6 +237,20 @@ struct StringMaker<std::tuple<Types...>> {
|
|||||||
};
|
};
|
||||||
#endif
|
#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 {
|
namespace Detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string makeString( T const& value ) {
|
std::string makeString( T const& value ) {
|
||||||
@ -244,6 +258,7 @@ namespace Detail {
|
|||||||
}
|
}
|
||||||
} // end namespace Detail
|
} // end namespace Detail
|
||||||
|
|
||||||
|
|
||||||
/// \brief converts any type to a string
|
/// \brief converts any type to a string
|
||||||
///
|
///
|
||||||
/// The default template forwards on to ostringstream - except when an
|
/// The default template forwards on to ostringstream - except when an
|
||||||
|
@ -1,23 +1,5 @@
|
|||||||
#include "catch.hpp"
|
#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]" )
|
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" );
|
||||||
|
@ -17,18 +17,6 @@
|
|||||||
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
|
||||||
#endif
|
#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
|
TEST_CASE
|
||||||
(
|
(
|
||||||
|
Loading…
Reference in New Issue
Block a user