catch_tostring: toString for std::tuple

This commit is contained in:
Andy Sawyer 2014-09-04 00:31:11 +01:00
parent 3196937343
commit 022a0b4fcb

View File

@ -193,6 +193,50 @@ struct StringMaker<std::vector<T, Allocator> > {
} }
}; };
#ifdef CATCH_CPP11_OR_GREATER
/*
toString for tuples
*/
namespace TupleDetail {
template<
typename Tuple,
std::size_t N = 0,
bool = (N < std::tuple_size<Tuple>::value)
>
struct ElementPrinter {
static void print( const Tuple& tuple, std::ostream& os )
{
os << ( N ? ", " : " " )
<< Catch::toString(std::get<N>(tuple));
ElementPrinter<Tuple,N+1>::print(tuple,os);
}
};
template<
typename Tuple,
std::size_t N
>
struct ElementPrinter<Tuple,N,false> {
static void print( const Tuple&, std::ostream& ) {}
};
}
template<typename ...Types>
struct StringMaker<std::tuple<Types...>> {
static std::string convert( const std::tuple<Types...>& tuple )
{
std::ostringstream os;
os << '{';
TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
os << " }";
return os.str();
}
};
#endif
namespace Detail { namespace Detail {
template<typename T> template<typename T>
std::string makeString( T const& value ) { std::string makeString( T const& value ) {