mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
catch_tostring : moved defintion of rangeToString
Detail::rangeToString is now defined after the various toString overloads. This results in them being accessible with rangeToString is instantiated (in this case, by StringMaker<vector>). This (sort-of) fixes the problem where contained types are toString'd incorrectly. Consider: std::vector<std::string> v { "abc" }; Before: Catch::toString( v ) == "{ abc }" After: Catch::toString( v ) == "{ "abc" }" (note the extra pair of quotes around the "abc" - these are added by Catch::toString( std::string ) which is now called by rangeToString)
This commit is contained in:
parent
0dbcf218c3
commit
d6f23a9a36
@ -101,18 +101,7 @@ struct StringMaker<T*> {
|
|||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
template<typename InputIterator>
|
template<typename InputIterator>
|
||||||
std::string rangeToString( InputIterator first, InputIterator last ) {
|
std::string rangeToString( InputIterator first, InputIterator last );
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "{ ";
|
|
||||||
if( first != last ) {
|
|
||||||
oss << toString( *first );
|
|
||||||
for( ++first ; first != last ; ++first ) {
|
|
||||||
oss << ", " << toString( *first );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
oss << " }";
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Allocator>
|
template<typename T, typename Allocator>
|
||||||
@ -238,6 +227,22 @@ inline std::string toString( std::nullptr_t ) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace Detail {
|
||||||
|
template<typename InputIterator>
|
||||||
|
std::string rangeToString( InputIterator first, InputIterator last ) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "{ ";
|
||||||
|
if( first != last ) {
|
||||||
|
oss << toString( *first );
|
||||||
|
for( ++first ; first != last ; ++first ) {
|
||||||
|
oss << ", " << toString( *first );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oss << " }";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user