diff options
| author | Phil Nash | 2014-12-30 18:43:38 +0000 |
|---|---|---|
| committer | Phil Nash | 2014-12-30 18:43:38 +0000 |
| commit | e8a99231b66c035562269b0efafd29d3dce58379 (patch) | |
| tree | 7e2be0722513f96fa72275fdf0ed46cc6edf9b54 /include | |
| parent | d76e08113b30997299200c654b27a71ec04af91b (diff) | |
| parent | 75a08bbc6c88826ba08d1ba6b2655c5200abc4a3 (diff) | |
| download | catch3-e8a99231b66c035562269b0efafd29d3dce58379.tar.gz | |
Merge branch 'PureAbstract-tuple_to_string' into develop
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_tostring.h | 105 |
1 files changed, 78 insertions, 27 deletions
diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 1c30b203..6265cf20 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -21,12 +21,46 @@ #include "catch_objc_arc.hpp" #endif +#ifdef CATCH_CPP11_OR_GREATER +#include <tuple> +#include <type_traits> +#endif + namespace Catch { // Why we're here. template<typename T> std::string toString( T const& value ); +// Built in overloads + +std::string toString( std::string const& value ); +std::string toString( std::wstring const& value ); +std::string toString( const char* const value ); +std::string toString( char* const value ); +std::string toString( const wchar_t* const value ); +std::string toString( wchar_t* const value ); +std::string toString( int value ); +std::string toString( unsigned long value ); +std::string toString( unsigned int value ); +std::string toString( const double value ); +std::string toString( const float value ); +std::string toString( bool value ); +std::string toString( char value ); +std::string toString( signed char value ); +std::string toString( unsigned char value ); + +#ifdef CATCH_CONFIG_CPP11_NULLPTR +std::string toString( std::nullptr_t ); +#endif + +#ifdef __OBJC__ + std::string toString( NSString const * const& nsstring ); + std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); + std::string toString( NSObject* const& nsObject ); +#endif + + namespace Detail { extern std::string unprintableString; @@ -166,6 +200,50 @@ std::string toString( std::vector<T,Allocator> const& v ) { return Detail::rangeToString( v.begin(), v.end() ); } + +#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 ) { @@ -185,33 +263,6 @@ std::string toString( T const& value ) { return StringMaker<T>::convert( value ); } -// Built in overloads - -std::string toString( std::string const& value ); -std::string toString( std::wstring const& value ); -std::string toString( const char* const value ); -std::string toString( char* const value ); -std::string toString( const wchar_t* const value ); -std::string toString( wchar_t* const value ); -std::string toString( int value ); -std::string toString( unsigned long value ); -std::string toString( unsigned int value ); -std::string toString( const double value ); -std::string toString( const float value ); -std::string toString( bool value ); -std::string toString( char value ); -std::string toString( signed char value ); -std::string toString( unsigned char value ); - -#ifdef CATCH_CONFIG_CPP11_NULLPTR -std::string toString( std::nullptr_t ); -#endif - -#ifdef __OBJC__ - std::string toString( NSString const * const& nsstring ); - std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); - std::string toString( NSObject* const& nsObject ); -#endif namespace Detail { template<typename InputIterator> |