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.