From de5109182c1c7c6b300f4b052ea2b88edd92b9a1 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 23 Sep 2024 09:53:57 +0200 Subject: [PATCH] graph: fixup --- ortools/graph/christofides.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ortools/graph/christofides.h b/ortools/graph/christofides.h index 3fb91ea79b..92bd1bfcce 100644 --- a/ortools/graph/christofides.h +++ b/ortools/graph/christofides.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -84,17 +85,15 @@ class ChristofidesPathSolver { private: // Safe addition operator to avoid overflows when possible. - template - struct Add { - static T apply(T a, T b) { return a + b; } - }; - template - struct Add { - static int64_t apply(int64_t a, int64_t b) { return CapAdd(a, b); } - }; template T SafeAdd(T a, T b) { - return Add::apply(a, b); + // TODO(user): use std::remove_cvref_t once C++20 is available. + if constexpr (std::is_same_v>, + int64_t> == true) { + return CapAdd(a, b); + } else { + return a + b; + } } // Matching algorithm to use.