Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
int_type.h File Reference
#include <stddef.h>
#include <functional>
#include <iosfwd>
#include <ostream>
#include <type_traits>
#include "absl/base/port.h"
#include "absl/strings/string_view.h"
#include "ortools/base/macros.h"

Go to the source code of this file.

Classes

class  gtl::IntType< IntTypeName, _ValueType >
 
struct  gtl::IntType< IntTypeName, _ValueType >::Hasher
 
struct  std::hash< gtl::IntType< IntTypeName, ValueType > >
 

Namespaces

namespace  gtl
 
namespace  std
 STL namespace.
 

Macros

#define DEFINE_INT_TYPE(int_type_name, value_type)
 
#define INT_TYPE_ASSIGNMENT_OP(op)
 
#define INT_TYPE_ARITHMETIC_OP(op)
 
#define INT_TYPE_COMPARISON_OP(op)
 

Functions

template<typename IntTypeName , typename ValueType >
std::ostream & gtl::operator<< (std::ostream &os, IntType< IntTypeName, ValueType > arg)
 
 gtl::INT_TYPE_ARITHMETIC_OP (+)
 
 gtl::INT_TYPE_ARITHMETIC_OP (-)
 
INT_TYPE_ARITHMETIC_OP * gtl::INT_TYPE_ARITHMETIC_OP (/);INT_TYPE_ARITHMETIC_OP(<<
 
 gtl::INT_TYPE_ARITHMETIC_OP (> >)
 
 gtl::INT_TYPE_ARITHMETIC_OP (%)
 
 gtl::INT_TYPE_COMPARISON_OP (==)
 
 gtl::INT_TYPE_COMPARISON_OP (!=)
 
 gtl::INT_TYPE_COMPARISON_OP (<=)
 
 gtl::INT_TYPE_COMPARISON_OP (>=)
 

Variables

class gtl::IntType gtl::ABSL_ATTRIBUTE_PACKED
 

Macro Definition Documentation

◆ DEFINE_INT_TYPE

#define DEFINE_INT_TYPE ( int_type_name,
value_type )
Value:
struct int_type_name##_tag_ { \
static constexpr absl::string_view TypeName() { return #int_type_name; } \
}; \
typedef ::gtl::IntType<int_type_name##_tag_, value_type> int_type_name;

Defines the IntType using value_type and typedefs it to int_type_name. The struct int_type_name ## tag trickery is needed to ensure that a new type is created per int_type_name.

Definition at line 167 of file int_type.h.

◆ INT_TYPE_ARITHMETIC_OP

#define INT_TYPE_ARITHMETIC_OP ( op)
Value:
template <typename IntTypeName, typename ValueType> \
constexpr IntType<IntTypeName, ValueType> operator op( \
IntType<IntTypeName, ValueType> id_1, \
IntType<IntTypeName, ValueType> id_2) { \
return IntType<IntTypeName, ValueType>(id_1.value() op id_2.value()); \
} \
template <typename IntTypeName, typename ValueType> \
constexpr IntType<IntTypeName, ValueType> operator op( \
IntType<IntTypeName, ValueType> id, \
typename IntType<IntTypeName, ValueType>::ValueType arg_val) { \
return IntType<IntTypeName, ValueType>(id.value() op arg_val); \
} \
template <typename IntTypeName, typename ValueType> \
constexpr IntType<IntTypeName, ValueType> operator op( \
typename IntType<IntTypeName, ValueType>::ValueType arg_val, \
IntType<IntTypeName, ValueType> id) { \
return IntType<IntTypeName, ValueType>(arg_val op id.value()); \
}
int64_t value

– NON-MEMBER ARITHMETIC OPERATORS ---------------------------------------— We support only the +, -, *, and / operators with the same IntType and ValueType types. The reason is to allow simple manipulation on these IDs when used as indices in vectors and arrays.

NB: Although it is possible to do IntType * IntType and IntType / IntType, it is probably non-sensical from a dimensionality analysis perspective.

Definition at line 297 of file int_type.h.

◆ INT_TYPE_ASSIGNMENT_OP

#define INT_TYPE_ASSIGNMENT_OP ( op)
Value:
ThisType& operator op(const ThisType & arg_value) { \
value_ op arg_value.value(); \
return *this; \
} \
ThisType& operator op(ValueType arg_value) { \
value_ op arg_value; \
return *this; \
}

– ASSIGNMENT OPERATORS ------------------------------------------------— We support the following assignment operators: =, +=, -=, *=, /=, <<=, >>= and %= for both ThisType and ValueType.

Definition at line 250 of file int_type.h.

◆ INT_TYPE_COMPARISON_OP

#define INT_TYPE_COMPARISON_OP ( op)
Value:
template <typename IntTypeName, typename ValueType> \
static inline constexpr bool operator op( \
IntType<IntTypeName, ValueType> id_1, \
IntType<IntTypeName, ValueType> id_2) { \
return id_1.value() op id_2.value(); \
} \
template <typename IntTypeName, typename ValueType> \
static inline constexpr bool operator op( \
IntType<IntTypeName, ValueType> id, \
typename IntType<IntTypeName, ValueType>::ValueType val) { \
return id.value() op val; \
} \
template <typename IntTypeName, typename ValueType> \
static inline constexpr bool operator op( \
typename IntType<IntTypeName, ValueType>::ValueType val, \
IntType<IntTypeName, ValueType> id) { \
return val op id.value(); \
}

– NON-MEMBER COMPARISON OPERATORS ---------------------------------------— Static inline comparison operators. We allow all comparison operators among the following types (OP \in [==, !=, <, <=, >, >=]: IntType<IntTypeName, ValueType> OP IntType<IntTypeName, ValueType> IntType<IntTypeName, ValueType> OP ValueType ValueType OP IntType<IntTypeName, ValueType>

Definition at line 331 of file int_type.h.