Progmasoft Git

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

StringRef appends itself to std::string efficiently

Commit
950ccf4749dc3324543c0cba44f85ff81dd300af
Author
Martin Hořeňovský ·
Parents
cf4b7eead927

Files · Download .tar.gz

Changes

 include/internal/catch_assertionresult.cpp | 4 ++--
 include/internal/catch_stringref.cpp       | 5 +++++
 include/internal/catch_stringref.h         | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/internal/catch_assertionresult.cpp b/include/internal/catch_assertionresult.cpp
index ec32c664..4ce07187 100644
--- a/include/internal/catch_assertionresult.cpp
+++ b/include/internal/catch_assertionresult.cpp
@@ -65,9 +65,9 @@ namespace Catch {
             expr = m_info.capturedExpression;
         else {
             expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
-            expr += m_info.macroName.c_str();
+            expr += m_info.macroName;
             expr += "( ";
-            expr += m_info.capturedExpression.c_str();
+            expr += m_info.capturedExpression;
             expr += " )";
         }
         return expr;
diff --git a/include/internal/catch_stringref.cpp b/include/internal/catch_stringref.cpp
index 604e8465..46b25039 100644
--- a/include/internal/catch_stringref.cpp
+++ b/include/internal/catch_stringref.cpp
@@ -115,6 +115,11 @@ namespace Catch {
         return os.write(str.m_start, str.m_size);
     }
 
+    auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
+        lhs.append(rhs.m_start, rhs.m_size);
+        return lhs;
+    }
+
 } // namespace Catch
 
 #if defined(__clang__)
diff --git a/include/internal/catch_stringref.h b/include/internal/catch_stringref.h
index 1c7e6cbe..beee2637 100644
--- a/include/internal/catch_stringref.h
+++ b/include/internal/catch_stringref.h
@@ -92,6 +92,8 @@ namespace Catch {
 
         auto operator[] ( size_type index ) const noexcept -> char;
 
+        friend auto operator += ( std::string& lhs, StringRef const& rhs ) -> std::string&;
+
     public: // named queries
         auto empty() const noexcept -> bool {
             return m_size == 0;