mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-25 05:59:24 +00:00
Add allocator support to StringMaker<vector>
- also extracted out 'rangeToString', in an attempt to make it easier to add support for other containers
This commit is contained in:
parent
1e2f1d1603
commit
0dbcf218c3
2 changed files with 31 additions and 15 deletions
|
@ -99,19 +99,27 @@ struct StringMaker<T*> {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct StringMaker<std::vector<T> > {
|
||||
static std::string convert( std::vector<T> const& v ) {
|
||||
namespace Detail {
|
||||
template<typename InputIterator>
|
||||
std::string rangeToString( InputIterator first, InputIterator last ) {
|
||||
std::ostringstream oss;
|
||||
oss << "{ ";
|
||||
for( std::size_t i = 0; i < v.size(); ++ i ) {
|
||||
oss << toString( v[i] );
|
||||
if( i < v.size() - 1 )
|
||||
oss << ", ";
|
||||
if( first != last ) {
|
||||
oss << toString( *first );
|
||||
for( ++first ; first != last ; ++first ) {
|
||||
oss << ", " << toString( *first );
|
||||
}
|
||||
}
|
||||
oss << " }";
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename Allocator>
|
||||
struct StringMaker<std::vector<T, Allocator> > {
|
||||
static std::string convert( std::vector<T,Allocator> const& v ) {
|
||||
return Detail::rangeToString( v.begin(), v.end() );
|
||||
}
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue