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

Avoid copying Clara::Parser for every inserted Opt

This prevents the full construction from being O(N^2) in number
of `Opt`s, and also reduces the number of allocations for running
no tests significantly:

`tests/SelfTest`: 7705 -> 6095
`tests/ExtraTests/NoTests` 2215 -> 605
Commit
c57e349d1d62fcdf96aef576a5c200ae2078daad
Author
Martin Hořeňovský ·
Parents
822c44a20395

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_clara.hpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp
index 8f6a4e9e..a9413810 100644
--- a/src/catch2/internal/catch_clara.hpp
+++ b/src/catch2/internal/catch_clara.hpp
@@ -636,8 +636,14 @@ namespace Catch {
             Parser& operator|=(Parser const& other);
 
             template <typename T>
-            auto operator|(T const& other) const -> Parser {
-                return Parser(*this) |= other;
+            friend Parser operator|(Parser const& p, T const& rhs) {
+                return Parser( p ) |= rhs;
+            }
+
+            template <typename T>
+            friend Parser operator|( Parser&& p, T const& rhs ) {
+                p |= rhs;
+                return CATCH_MOVE(p);
             }
 
             std::vector<Detail::HelpColumns> getHelpColumns() const;