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

Move some compile-time dispatch to runtime

The runtime performance is likely to be negligible,
but compile times need every improvement they can get.
Commit
85e14c5fb53a413dff7cba1bb196b6e619ee1d0f
Author
Martin Hořeňovský ·
Parents
feca97dfde80

Files · Download .tar.gz

Changes

 CMakeLists.txt                            |  1 +
 include/internal/catch_evaluate.cpp       | 38 +++++++++++++++++++++++++++++++
 include/internal/catch_evaluate.hpp       | 12 ++--------
 include/internal/catch_expression_lhs.hpp |  2 +-
 4 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 715ac0ae..05cc5c8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -204,6 +204,7 @@ set(IMPL_SOURCES
         ${HEADER_DIR}/internal/catch_context.cpp
         ${HEADER_DIR}/internal/catch_debugger.cpp
         ${HEADER_DIR}/internal/catch_errno_guard.cpp
+        ${HEADER_DIR}/internal/catch_evaluate.cpp
         ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp
         ${HEADER_DIR}/internal/catch_fatal_condition.cpp
         ${HEADER_DIR}/internal/catch_list.cpp
diff --git a/include/internal/catch_evaluate.cpp b/include/internal/catch_evaluate.cpp
new file mode 100644
index 00000000..349f71e7
--- /dev/null
+++ b/include/internal/catch_evaluate.cpp
@@ -0,0 +1,38 @@
+/*
+ *  Created by Martin on 01/08/2017.
+ *
+ *  Distributed under the Boost Software License, Version 1.0. (See accompanying
+ *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#include "catch_evaluate.hpp"
+
+#include "catch_enforce.h"
+
+namespace Catch {
+namespace Internal {
+
+    const char* operatorName(Operator op) {
+        switch (op) {
+            case IsEqualTo:
+                return "==";
+            case IsNotEqualTo:
+                return "!=";
+            case IsLessThan:
+                return "<";
+            case IsGreaterThan:
+                return ">";
+            case IsLessThanOrEqualTo:
+                return "<=";
+            case IsGreaterThanOrEqualTo:
+                return ">=";
+            default:
+                CATCH_ERROR("Attempting to translate unknown operator!");
+        }
+    }
+
+    // nullptr_t support based on pull request #154 from Konstantin Baumann
+    std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
+
+} // end of namespace Internal
+} // end of namespace Catch
diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp
index 1ee53d74..730032fd 100644
--- a/include/internal/catch_evaluate.hpp
+++ b/include/internal/catch_evaluate.hpp
@@ -28,19 +28,11 @@ namespace Internal {
         IsGreaterThanOrEqualTo
     };
 
-    template<Operator Op> struct OperatorTraits             { static const char* getName(){ return "*error*"; } };
-    template<> struct OperatorTraits<IsEqualTo>             { static const char* getName(){ return "=="; } };
-    template<> struct OperatorTraits<IsNotEqualTo>          { static const char* getName(){ return "!="; } };
-    template<> struct OperatorTraits<IsLessThan>            { static const char* getName(){ return "<"; } };
-    template<> struct OperatorTraits<IsGreaterThan>         { static const char* getName(){ return ">"; } };
-    template<> struct OperatorTraits<IsLessThanOrEqualTo>   { static const char* getName(){ return "<="; } };
-    template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
+    const char* operatorName(Operator op);
 
     template<typename T>
     T& opCast(T const& t) { return const_cast<T&>(t); }
-
-    // nullptr_t support based on pull request #154 from Konstantin Baumann
-    inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
+    std::nullptr_t opCast(std::nullptr_t);
 
 
     // So the compare overloads can be operator agnostic we convey the operator as a template
diff --git a/include/internal/catch_expression_lhs.hpp b/include/internal/catch_expression_lhs.hpp
index 67db9d65..192f001a 100644
--- a/include/internal/catch_expression_lhs.hpp
+++ b/include/internal/catch_expression_lhs.hpp
@@ -134,7 +134,7 @@ public:
                    // 1 for negation (conditionally added later)
         dest = lhs;
         dest += delim;
-        dest += Internal::OperatorTraits<Op>::getName();
+        dest += Internal::operatorName(Op);
         dest += delim;
         dest += rhs;
     }