diff --git a/Testing/printDebugging.h b/Testing/printDebugging.h index 9610a3f..c6f86de 100644 --- a/Testing/printDebugging.h +++ b/Testing/printDebugging.h @@ -41,10 +41,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m using namespace std::literals::string_literals; template< OutputMode outputMode, typename T > - std::string - stringifyValue( const T &v ) + void + streamValue( const T &v, std::ostream &oss ) { - std::ostringstream oss; if constexpr( false ) ; // To keep the rest of the clauses regular else if constexpr( std::is_same_v< std::uint8_t, std::decay_t< T > > ) { @@ -68,11 +67,12 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m } else if constexpr( Meta::is_ostreamable_v< T > ) { - return IOStreams::stringify( v ); + oss << v; } else if constexpr( Meta::is_optional_v< T > ) { - return v.has_value() ? stringifyValue< outputMode >( v.value() ) : ""s; + if( not v.has_value() ) oss << ""; + else streamValue< outputMode >( v.value(), oss ); } else if constexpr( Meta::is_sequence_v< T > ) { @@ -85,14 +85,19 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m oss << Meta::sequence_kind_v< T > << "(" << v.size() << " elements):\n{" << std::endl; int index= 0; - for( const auto &elem: v ) oss << "\t" << index++ << ": " << stringifyValue< outputMode >( elem ) << "," << std::endl; + for( const auto &elem: v ) + { + oss << "\t" << index++ << ": "; + streamValue< outputMode >( elem, oss ); + oss << "," << std::endl; + } oss << "}" << std::endl; } } else if constexpr( Meta::is_pair_v< T > ) { const auto &[ first, second ]= v; - return stringifyValue< outputMode >( std::tie( first, second ) ); + streamValue< outputMode >( std::tie( first, second ), oss ); } else if constexpr( Meta::is_tuple_v< T > ) { @@ -101,7 +106,8 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m { if( not first ) oss << ", "; first= false; - oss << std::endl << stringifyValue< outputMode >( elem ); + oss << std::endl; + streamValue< outputMode >( elem, oss ); }; oss << std::endl << ']' << std::endl; } @@ -109,7 +115,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m { if( false ) ; // For alignment else if( v == TotalOrder::less ) oss << "less"; - else if ( v == TotalOrder::equal ) oss << "equal"; + else if( v == TotalOrder::equal ) oss << "equal"; else if( v == TotalOrder::greater ) oss << "greater"; else throw std::logic_error( "Impossible `TotalOrder` condition." ); } @@ -117,6 +123,14 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m { static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." ); } + } + + template< OutputMode outputMode, typename T > + std::string + stringifyValue( const T &v ) + { + std::ostringstream oss; + streamValue< outputMode >( v, oss ); return std::move( oss ).str(); }