catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Add allocator support to StringMaker<vector>
- Commit
0dbcf218c353e801d4fa26d14696e81f6b832cad- Author
- Andy Sawyer ·
- Parents
1e2f1d160336
Changes
include/internal/catch_tostring.hpp | 22 +++++++++++++++------- single_include/catch.hpp | 24 ++++++++++++++++-------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index 78c725ec..48bc6830 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -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 { diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 523fa088..00dd9fc5 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* * CATCH v1.0 build 10 (master branch) - * Generated: 2013-09-14 19:56:34.776409 + * Generated: 2013-09-17 22:21:47.780755 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -722,19 +722,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 {