Skip to content

Commit

Permalink
fixup 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 8, 2023
1 parent 66e128a commit be8ad02
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions ortools/math_opt/cpp/variable_and_expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename V>
using VariableMap = absl::flat_hash_map<Variable, V>;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be8ad02

Please sign in to comment.