50#ifndef OR_TOOLS_UTIL_STRONG_INTEGERS_H_
51#define OR_TOOLS_UTIL_STRONG_INTEGERS_H_
61#include "absl/base/port.h"
62#include "absl/strings/string_view.h"
72#define DEFINE_STRONG_INDEX_TYPE(index_type_name) \
73 struct index_type_name##_index_tag_ { \
74 static constexpr absl::string_view TypeName() { return #index_type_name; } \
76 typedef ::operations_research::StrongIndex<index_type_name##_index_tag_> \
83#define DEFINE_STRONG_INT64_TYPE(integer_type_name) \
84 struct integer_type_name##_integer_tag_ { \
85 static constexpr absl::string_view TypeName() { \
86 return #integer_type_name; \
89 typedef ::operations_research::StrongInt64<integer_type_name##_integer_tag_> \
99#define STRONG_ASSIGNMENT_OP(StrongClass, IntType, op) \
100 ThisType& operator op(const ThisType& arg_value) { \
101 value_ op arg_value.value(); \
104 ThisType& operator op(IntType arg_value) { \
105 value_ op arg_value; \
109#define INCREMENT_AND_DECREMENT_OPERATORS \
110 ThisType& operator++() { \
114 const ThisType operator++(int v) { \
115 ThisType temp(*this); \
119 ThisType& operator--() { \
123 const ThisType operator--(int v) { \
124 ThisType temp(*this); \
137template <
typename StrongIndexName>
144 return StrongIndexName::TypeName();
149 return static_cast<size_t>(x.
value());
167 constexpr int value()
const {
return value_; }
169 template <
typename ValType>
171 return static_cast<ValType
>(value_);
194template <
typename StrongIntegerName>
201 return StrongIntegerName::TypeName();
206 return static_cast<size_t>(x.
value());
221 constexpr int64_t
value()
const {
return value_; }
223 template <
typename ValType>
225 return static_cast<ValType
>(value_);
246#undef STRONG_ASSIGNMENT_OP
247#undef INCREMENT_AND_DECREMENT_OPERATORS
252template <
typename StrongIndexName>
255 return os << arg.
value();
258template <
typename StrongIntegerName>
261 return os << arg.
value();
265#define STRONG_TYPE_ARITHMETIC_OP(StrongType, IntType, op) \
266 template <typename StrongName> \
267 constexpr StrongType<StrongName> operator op(StrongType<StrongName> id_1, \
268 StrongType<StrongName> id_2) { \
269 return StrongType<StrongName>(id_1.value() op id_2.value()); \
271 template <typename StrongName> \
272 constexpr StrongType<StrongName> operator op(StrongType<StrongName> id, \
274 return StrongType<StrongName>(id.value() op arg_val); \
276 template <typename StrongName> \
277 constexpr StrongType<StrongName> operator op(IntType arg_val, \
278 StrongType<StrongName> id) { \
279 return StrongType<StrongName>(arg_val op id.value()); \
294#undef STRONG_TYPE_ARITHMETIC_OP
297#define STRONG_TYPE_COMPARISON_OP(StrongType, IntType, op) \
298 template <typename StrongName> \
299 static inline constexpr bool operator op(StrongType<StrongName> id_1, \
300 StrongType<StrongName> id_2) { \
301 return id_1.value() op id_2.value(); \
303 template <typename StrongName> \
304 static inline constexpr bool operator op(StrongType<StrongName> id, \
306 return id.value() op val; \
308 template <typename StrongName> \
309 static inline constexpr bool operator op(IntType val, \
310 StrongType<StrongName> id) { \
311 return val op id.value(); \
327#undef STRONG_TYPE_COMPARISON_OP
330template <
typename StrongIndexName,
typename H>
332 return H::combine(std::move(h), i.
value());
335template <
typename StrongIntegerName,
typename H>
337 return H::combine(std::move(h), i.
value());
344template <
typename Tag>
348template <
typename Tag>
STRONG_ASSIGNMENT_OP(StrongIndex, int, -=)
struct ABSL_DEPRECATED("Use absl::Hash instead") Hasher
StrongIndex< StrongIndexName > ThisType
constexpr StrongIndex(int value)
INCREMENT_AND_DECREMENT_OPERATORS
constexpr const ThisType operator+() const
constexpr int value() const
STRONG_ASSIGNMENT_OP(StrongIndex, int,+=)
constexpr const ThisType operator-() const
constexpr ValType value() const
StrongIndex & operator=(int arg_value)
static constexpr absl::string_view TypeName()
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, > >=)
StrongInt64 & operator=(int64_t arg_value)
struct ABSL_DEPRECATED("Use absl::Hash instead") Hasher
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, *=)
StrongInt64< StrongIntegerName > ThisType
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t,+=)
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t,<<=)
INCREMENT_AND_DECREMENT_OPERATORS
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t,/=)
constexpr const ThisType operator+() const
constexpr const ThisType operator~() const
constexpr const ThisType operator-() const
constexpr ValType value() const
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, -=)
constexpr int64_t value() const
constexpr StrongInt64(int64_t value)
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, %=)
static constexpr absl::string_view TypeName()
Collection of objects used to extend the Constraint Solver library.
H AbslHashValue(H h, const StrongIndex< StrongIndexName > &i)
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
STRONG_TYPE_ARITHMETIC_OP(StrongIndex, int,+)
STRONG_TYPE_COMPARISON_OP(StrongIndex, int,==)
uint64_t Hash(uint64_t num, uint64_t c)