From be8ad02569716e7af0f311149aa71c6b3441049d Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Fri, 8 Sep 2023 09:54:44 +0200 Subject: [PATCH] fixup 5 --- .../math_opt/cpp/variable_and_expressions.h | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/ortools/math_opt/cpp/variable_and_expressions.h b/ortools/math_opt/cpp/variable_and_expressions.h index 275c96d65b..c35c80d265 100644 --- a/ortools/math_opt/cpp/variable_and_expressions.h +++ b/ortools/math_opt/cpp/variable_and_expressions.h @@ -151,6 +151,54 @@ class Variable { VariableId id_; }; +namespace internal { + +// The result of the equality comparison between two Variable. +// +// We use an object here to delay the evaluation of equality so that we can use +// the operator== in two use-cases: +// +// 1. when the user want to test that two Variable values references the same +// variable. This is supported by having this object support implicit +// conversion to bool. +// +// 2. when the user want to use the equality to create a constraint of equality +// between two variables. +struct VariablesEquality { + // Users are not expected to call this constructor. Instead they should only + // use the overload of `operator==` that returns this when comparing two + // Variable. For example `x == y`. + inline VariablesEquality(Variable lhs, Variable rhs); + inline operator bool() const; // NOLINT + Variable lhs; + Variable rhs; +}; + +} // namespace internal + +inline internal::VariablesEquality operator==(const Variable& lhs, + const Variable& rhs); +inline bool operator!=(const Variable& lhs, const Variable& rhs); + +} // namespace math_opt +} // namespace operations_research + +#if defined(_MSC_VER) +namespace std { + template<> + struct equal_to<::operations_research::math_opt::Variable> { + constexpr bool operator()( + const ::operations_research::math_opt::Variable& lhs, + const ::operations_research::math_opt::Variable& rhs ) const { + return lhs == rhs; + } + }; +} // namespace std +#endif + +namespace operations_research { +namespace math_opt { + template using VariableMap = absl::flat_hash_map; @@ -463,54 +511,6 @@ inline LinearExpression operator*(LinearExpression lhs, double rhs); inline LinearExpression operator*(double lhs, LinearExpression rhs); inline LinearExpression operator/(LinearExpression lhs, double rhs); -namespace internal { - -// The result of the equality comparison between two Variable. -// -// We use an object here to delay the evaluation of equality so that we can use -// the operator== in two use-cases: -// -// 1. when the user want to test that two Variable values references the same -// variable. This is supported by having this object support implicit -// conversion to bool. -// -// 2. when the user want to use the equality to create a constraint of equality -// between two variables. -struct VariablesEquality { - // Users are not expected to call this constructor. Instead they should only - // use the overload of `operator==` that returns this when comparing two - // Variable. For example `x == y`. - inline VariablesEquality(Variable lhs, Variable rhs); - inline operator bool() const; // NOLINT - Variable lhs; - Variable rhs; -}; - -} // namespace internal - -inline internal::VariablesEquality operator==(const Variable& lhs, - const Variable& rhs); -inline bool operator!=(const Variable& lhs, const Variable& rhs); - -} // namespace math_opt -} // namespace operations_research - -#if defined(_MSC_VER) -namespace std { - template<> - struct equal_to<::operations_research::math_opt::Variable> { - constexpr bool operator()( - const ::operations_research::math_opt::Variable& lhs, - const ::operations_research::math_opt::Variable& rhs ) const { - return lhs == rhs; - } - }; -} // namespace std -#endif - -namespace operations_research { -namespace math_opt { - // A LinearExpression with a lower bound. struct LowerBoundedLinearExpression { // Users are not expected to use this constructor. Instead, they should build