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

Go to the source code of this file.

Classes

class  util_intops::StrongInt< StrongIntName, _ValueType >
 
struct  util_intops::StrongInt< StrongIntName, _ValueType >::Hasher
 
class  util_intops::StrongIntRange< IntType >
 
class  util_intops::StrongIntRange< IntType >::StrongIntRangeIterator
 Iterator over the indices. More...
 
struct  std::hash< util_intops::StrongInt< StrongIntName, ValueType > >
 

Namespaces

namespace  util_intops
 
namespace  std
 STL namespace.
 

Macros

#define DEFINE_STRONG_INT_TYPE(int_type_name, value_type)
 
#define STRONG_INT_TYPE_ASSIGNMENT_OP(op)
 
#define STRONG_INT_TYPE_ARITHMETIC_OP(op)
 
#define STRONG_INT_TYPE_COMPARISON_OP(op)
 

Functions

template<typename StrongIntName , typename ValueType >
std::ostream & util_intops::operator<< (std::ostream &os, StrongInt< StrongIntName, ValueType > arg)
 
template<typename Sink , typename... T>
void util_intops::AbslStringify (Sink &sink, StrongInt< T... > arg)
 
 util_intops::STRONG_INT_TYPE_ARITHMETIC_OP (+)
 
 util_intops::STRONG_INT_TYPE_ARITHMETIC_OP (-)
 
STRONG_INT_TYPE_ARITHMETIC_OP * util_intops::STRONG_INT_TYPE_ARITHMETIC_OP (/);STRONG_INT_TYPE_ARITHMETIC_OP(<<
 
 util_intops::STRONG_INT_TYPE_ARITHMETIC_OP (> >)
 
 util_intops::STRONG_INT_TYPE_ARITHMETIC_OP (%)
 
 util_intops::STRONG_INT_TYPE_COMPARISON_OP (==)
 
 util_intops::STRONG_INT_TYPE_COMPARISON_OP (!=)
 
 util_intops::STRONG_INT_TYPE_COMPARISON_OP (<=)
 
 util_intops::STRONG_INT_TYPE_COMPARISON_OP (>=)
 
template<typename IntType >
StrongIntRange< IntType > util_intops::MakeStrongIntRange (IntType end)
 
template<typename IntType >
StrongIntRange< IntType > util_intops::MakeStrongIntRange (IntType begin, IntType end)
 

Variables

class util_intops::StrongInt util_intops::ABSL_ATTRIBUTE_PACKED
 

Macro Definition Documentation

◆ DEFINE_STRONG_INT_TYPE

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

Defines the StrongInt 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 168 of file strong_int.h.

◆ STRONG_INT_TYPE_ARITHMETIC_OP

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

– NON-MEMBER ARITHMETIC OPERATORS ---------------------------------------— We support only the +, -, *, and / operators with the same StrongInt 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 StrongInt * StrongInt and StrongInt / StrongInt, it is probably non-sensical from a dimensionality analysis perspective.

Definition at line 327 of file strong_int.h.

◆ STRONG_INT_TYPE_ASSIGNMENT_OP

#define STRONG_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 262 of file strong_int.h.

◆ STRONG_INT_TYPE_COMPARISON_OP

#define STRONG_INT_TYPE_COMPARISON_OP ( op)
Value:
template <typename StrongIntName, typename ValueType> \
static inline constexpr bool operator op( \
StrongInt<StrongIntName, ValueType> id_1, \
StrongInt<StrongIntName, ValueType> id_2) { \
return id_1.value() op id_2.value(); \
} \
template <typename StrongIntName, typename ValueType> \
static inline constexpr bool operator op( \
StrongInt<StrongIntName, ValueType> id, \
typename StrongInt<StrongIntName, ValueType>::ValueType val) { \
return id.value() op val; \
} \
template <typename StrongIntName, typename ValueType> \
static inline constexpr bool operator op( \
typename StrongInt<StrongIntName, ValueType>::ValueType val, \
StrongInt<StrongIntName, 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 [==, !=, <, <=, >, >=]: StrongInt<StrongIntName, ValueType> OP StrongInt<StrongIntName, ValueType> StrongInt<StrongIntName, ValueType> OP ValueType ValueType OP StrongInt<StrongIntName, ValueType>

Definition at line 361 of file strong_int.h.