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

Enable moving Opts into Parser

This also required keeping the reference type in the fluent interface
for Opts.

Removes another ~40 allocations.
Commit
5d5f42f99b7409b6b051182fae69fd22f8877a6d
Author
Martin Hořeňovský ·
Parents
c57e349d1d62

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_clara.hpp | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp
index a9413810..4bcef406 100644
--- a/src/catch2/internal/catch_clara.hpp
+++ b/src/catch2/internal/catch_clara.hpp
@@ -495,10 +495,14 @@ namespace Catch {
                     m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
                     m_hint( hint ) {}
 
-                auto operator()( StringRef description ) -> DerivedT& {
+                DerivedT& operator()( StringRef description ) & {
                     m_description = description;
                     return static_cast<DerivedT&>( *this );
                 }
+                DerivedT&& operator()( StringRef description ) && {
+                    m_description = description;
+                    return static_cast<DerivedT&&>( *this );
+                }
 
                 auto optional() -> DerivedT& {
                     m_optionality = Optionality::Optional;
@@ -567,10 +571,14 @@ namespace Catch {
             Opt( T& ref, StringRef hint ):
                 ParserRefImpl( ref, hint ) {}
 
-            auto operator[](std::string const& optName) -> Opt& {
+            Opt& operator[]( std::string const& optName ) & {
                 m_optNames.push_back(optName);
                 return *this;
             }
+            Opt&& operator[]( std::string const& optName ) && {
+                m_optNames.push_back( optName );
+                return CATCH_MOVE(*this);
+            }
 
             Detail::HelpColumns getHelpColumns() const;
 
@@ -628,21 +636,25 @@ namespace Catch {
                 return *this;
             }
 
-            auto operator|=(Opt const& opt) -> Parser& {
-                m_options.push_back(opt);
-                return *this;
+            friend Parser& operator|=( Parser& p, Opt const& opt ) {
+                p.m_options.push_back( opt );
+                return p;
+            }
+            friend Parser& operator|=( Parser& p, Opt&& opt ) {
+                p.m_options.push_back( CATCH_MOVE(opt) );
+                return p;
             }
 
             Parser& operator|=(Parser const& other);
 
             template <typename T>
-            friend Parser operator|(Parser const& p, T const& rhs) {
-                return Parser( p ) |= rhs;
+            friend Parser operator|( Parser const& p, T&& rhs ) {
+                return Parser( p ) |= CATCH_FORWARD(rhs);
             }
 
             template <typename T>
-            friend Parser operator|( Parser&& p, T const& rhs ) {
-                p |= rhs;
+            friend Parser operator|( Parser&& p, T&& rhs ) {
+                p |= CATCH_FORWARD(rhs);
                 return CATCH_MOVE(p);
             }