Skip to content

Commit

Permalink
graph: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 23, 2024
1 parent 601830f commit de51091
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ortools/graph/christofides.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <cstdint>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -84,17 +85,15 @@ class ChristofidesPathSolver {

private:
// Safe addition operator to avoid overflows when possible.
template <typename T, typename DUMMY = void>
struct Add {
static T apply(T a, T b) { return a + b; }
};
template <typename DUMMY>
struct Add<int64_t, DUMMY> {
static int64_t apply(int64_t a, int64_t b) { return CapAdd(a, b); }
};
template <typename T>
T SafeAdd(T a, T b) {
return Add<T>::apply(a, b);
// TODO(user): use std::remove_cvref_t<T> once C++20 is available.
if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>,
int64_t> == true) {
return CapAdd(a, b);
} else {
return a + b;
}
}

// Matching algorithm to use.
Expand Down

0 comments on commit de51091

Please sign in to comment.