From af3f2499bcc89d25f4f9eed4c747366f9ef49ec1 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 4 Jan 2018 09:30:06 +0000 Subject: [PATCH] Added generic container detection in StringMaker. Removed vector specialisation as this is now covered generically - as are any containers that can be called via (freestanding) begin/ end --- include/internal/catch_tostring.h | 33 ++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 79e02448..92161709 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -60,7 +60,7 @@ namespace Catch { } // namespace Detail // If we decide for C++14, change these to enable_if_ts - template + template struct StringMaker { template static @@ -233,12 +233,6 @@ namespace Catch { } } - template - struct StringMaker > { - static std::string convert( std::vector const& v ) { - return ::Catch::Detail::rangeToString( v.begin(), v.end() ); - } - }; template struct EnumStringMaker { @@ -344,6 +338,31 @@ namespace Catch { } #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER +namespace Catch { + struct not_this_one {}; // Tag type for detecting which begin/ end are being selected + + // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace + using std::begin; + using std::end; + + not_this_one begin( ... ); + not_this_one end( ... ); + + template + struct is_range { + static const bool value = + !std::is_same())), not_this_one>::value && + !std::is_same())), not_this_one>::value; + }; + + template + struct StringMaker::value>::type> { + static std::string convert( R const& range ) { + return ::Catch::Detail::rangeToString( begin( range ), end( range ) ); + } + }; + +} // namespace Catch // Separate std::chrono::duration specialization #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)