mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
catch_tostring: toString for std::tuple
This commit is contained in:
parent
3196937343
commit
022a0b4fcb
@ -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 {
|
||||
template<typename T>
|
||||
std::string makeString( T const& value ) {
|
||||
|
Loading…
Reference in New Issue
Block a user