Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal
diff options
context:
space:
mode:
authorAndy Sawyer2014-09-04 00:31:11 +0100
committerAndy Sawyer2014-09-04 00:31:11 +0100
commit022a0b4fcb742afa3eeaea96ef01bedd22ea6e74 (patch)
treeaa5e18001b0b3c7646df0f39c09c89e99b2ac5d0 /include/internal
parent31969373437700ad989875be2dd63d5408663b56 (diff)
downloadcatch3-022a0b4fcb742afa3eeaea96ef01bedd22ea6e74.tar.gz
catch_tostring: toString for std::tuple
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/catch_tostring.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h
index 097219bb..cf60547f 100644
--- a/include/internal/catch_tostring.h
+++ b/include/internal/catch_tostring.h
@@ -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 ) {