From 46bf7605f41a97535f63abfb2406ec408573b441 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Thu, 20 Jul 2017 23:50:07 +0100 Subject: [PATCH] Hold exception translators by unique_ptr - and removed range deleters --- include/internal/catch_common.h | 10 ---------- .../internal/catch_exception_translator_registry.cpp | 3 +-- include/internal/catch_exception_translator_registry.h | 3 ++- include/internal/catch_interfaces_exception.h | 4 ++-- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index 6f037c71..bc9a0aba 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -45,16 +45,6 @@ namespace Catch { virtual ~NonCopyable(); }; - template - void deleteAll( ContainerT& container ) { - for( auto p : container ) - delete p; - } - template - void deleteAllValues( AssociativeContainerT& container ) { - for( auto const& kvp : container ) - delete kvp.second; - } bool startsWith( std::string const& s, std::string const& prefix ); bool startsWith( std::string const& s, char prefix ); diff --git a/include/internal/catch_exception_translator_registry.cpp b/include/internal/catch_exception_translator_registry.cpp index 18e7c0b6..1a857535 100644 --- a/include/internal/catch_exception_translator_registry.cpp +++ b/include/internal/catch_exception_translator_registry.cpp @@ -16,11 +16,10 @@ namespace Catch { ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() { - deleteAll( m_translators ); } void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( translator ); + m_translators.push_back( std::unique_ptr( translator ) ); } std::string ExceptionTranslatorRegistry::translateActiveException() const { diff --git a/include/internal/catch_exception_translator_registry.h b/include/internal/catch_exception_translator_registry.h index dc5d8159..d3059f48 100644 --- a/include/internal/catch_exception_translator_registry.h +++ b/include/internal/catch_exception_translator_registry.h @@ -11,6 +11,7 @@ #include "catch_interfaces_exception.h" #include #include +#include namespace Catch { @@ -22,7 +23,7 @@ namespace Catch { std::string tryTranslators() const; private: - std::vector m_translators; + std::vector> m_translators; }; } diff --git a/include/internal/catch_interfaces_exception.h b/include/internal/catch_interfaces_exception.h index 6387ba9d..32487ffa 100644 --- a/include/internal/catch_interfaces_exception.h +++ b/include/internal/catch_interfaces_exception.h @@ -18,7 +18,7 @@ namespace Catch { typedef std::string(*exceptionTranslateFunction)(); struct IExceptionTranslator; - typedef std::vector ExceptionTranslators; + typedef std::vector> ExceptionTranslators; struct IExceptionTranslator { virtual ~IExceptionTranslator(); @@ -40,7 +40,7 @@ namespace Catch { : m_translateFunction( translateFunction ) {} - virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { + std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { try { if( it == itEnd ) throw;