145#ifndef OR_TOOLS_BASE_INT_TYPE_H_
146#define OR_TOOLS_BASE_INT_TYPE_H_
152#include <type_traits>
154#include "absl/base/attributes.h"
155#include "absl/strings/string_view.h"
159template <
typename IntTypeName,
typename _ValueType>
165#define DEFINE_INT_TYPE(int_type_name, value_type) \
166 struct int_type_name##_tag_ { \
167 static constexpr absl::string_view TypeName() { return #int_type_name; } \
169 typedef ::gtl::IntType<int_type_name##_tag_, value_type> int_type_name;
181template <
typename IntTypeName,
typename _ValueType>
188 return IntTypeName::TypeName();
194 return static_cast<size_t>(arg.
value());
198 template <
typename H>
200 return H::combine(std::move(h), i.value());
219 template <
typename ValType>
221 return static_cast<ValType
>(value_);
244 constexpr bool operator!()
const {
return value_ == 0; }
252#define INT_TYPE_ASSIGNMENT_OP(op) \
253 ThisType& operator op(const ThisType& arg_value) { \
254 value_ op arg_value.value(); \
257 ThisType& operator op(ValueType arg_value) { \
258 value_ op arg_value; \
268#undef INT_TYPE_ASSIGNMENT_OP
283template <
typename IntTypeName,
typename ValueType>
286 return os << arg.
value();
296#define INT_TYPE_ARITHMETIC_OP(op) \
297 template <typename IntTypeName, typename ValueType> \
298 constexpr IntType<IntTypeName, ValueType> operator op( \
299 IntType<IntTypeName, ValueType> id_1, \
300 IntType<IntTypeName, ValueType> id_2) { \
301 return IntType<IntTypeName, ValueType>(id_1.value() op id_2.value()); \
303 template <typename IntTypeName, typename ValueType> \
304 constexpr IntType<IntTypeName, ValueType> operator op( \
305 IntType<IntTypeName, ValueType> id, \
306 typename IntType<IntTypeName, ValueType>::ValueType arg_val) { \
307 return IntType<IntTypeName, ValueType>(id.value() op arg_val); \
309 template <typename IntTypeName, typename ValueType> \
310 constexpr IntType<IntTypeName, ValueType> operator op( \
311 typename IntType<IntTypeName, ValueType>::ValueType arg_val, \
312 IntType<IntTypeName, ValueType> id) { \
313 return IntType<IntTypeName, ValueType>(arg_val op id.value()); \
322#undef INT_TYPE_ARITHMETIC_OP
330#define INT_TYPE_COMPARISON_OP(op) \
331 template <typename IntTypeName, typename ValueType> \
332 static inline constexpr bool operator op( \
333 IntType<IntTypeName, ValueType> id_1, \
334 IntType<IntTypeName, ValueType> id_2) { \
335 return id_1.value() op id_2.value(); \
337 template <typename IntTypeName, typename ValueType> \
338 static inline constexpr bool operator op( \
339 IntType<IntTypeName, ValueType> id, \
340 typename IntType<IntTypeName, ValueType>::ValueType val) { \
341 return id.value() op val; \
343 template <typename IntTypeName, typename ValueType> \
344 static inline constexpr bool operator op( \
345 typename IntType<IntTypeName, ValueType>::ValueType val, \
346 IntType<IntTypeName, ValueType> id) { \
347 return val op id.value(); \
355#undef INT_TYPE_COMPARISON_OP
const ThisType operator++(int v)
constexpr const ThisType operator~() const
constexpr ValType value() const
INT_TYPE_ASSIGNMENT_OP(+=)
constexpr const ThisType operator-() const
INT_TYPE_ASSIGNMENT_OP * INT_TYPE_ASSIGNMENT_OP(/=);INT_TYPE_ASSIGNMENT_OP(<<=
INT_TYPE_ASSIGNMENT_OP(%=)
static constexpr absl::string_view TypeName()
INT_TYPE_ASSIGNMENT_OP(> >=)
constexpr ValueType value() const
constexpr bool operator!() const
friend H AbslHashValue(H h, const IntType &i)
const ThisType operator--(int v)
constexpr const ThisType operator+() const
ThisType & operator++()
– UNARY OPERATORS -----------------------------------------------------—
constexpr IntType(ValueType value)
C'tor explicitly initializing from a ValueType.
constexpr IntType()
Default constructor initializing value_ to 0.
ThisType & operator=(ValueType arg_value)
IntType< IntTypeName, ValueType > ThisType
INT_TYPE_ASSIGNMENT_OP(-=)
#define INT_TYPE_ASSIGNMENT_OP(op)
#define INT_TYPE_ARITHMETIC_OP(op)
INT_TYPE_COMPARISON_OP(==)
std::ostream & operator<<(std::ostream &os, IntType< IntTypeName, ValueType > arg)
class gtl::IntType ABSL_ATTRIBUTE_PACKED
size_t operator()(const IntType &arg) const