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

Go to the source code of this file.

Classes

class  operations_research::StrongIndex< StrongIndexName >
 
class  operations_research::StrongInt64< StrongIntegerName >
 
struct  std::hash< operations_research::StrongIndex< Tag > >
 
struct  std::hash< operations_research::StrongInt64< Tag > >
 
struct  std::numeric_limits< operations_research::StrongIndex< Tag > >
 
struct  std::numeric_limits< operations_research::StrongInt64< Tag > >
 

Namespaces

namespace  operations_research
 In SWIG mode, we don't want anything besides these top-level includes.
 
namespace  std
 STL namespace.
 

Macros

#define DEFINE_STRONG_INDEX_TYPE(index_type_name)
 
#define DEFINE_STRONG_INT64_TYPE(integer_type_name)
 
#define STRONG_ASSIGNMENT_OP(StrongClass, IntType, op)
 --------— Implementation ---------—
 
#define INCREMENT_AND_DECREMENT_OPERATORS
 
#define STRONG_TYPE_ARITHMETIC_OP(StrongType, IntType, op)
 – NON-MEMBER ARITHMETIC OPERATORS ---------------------------------------—
 
#define STRONG_TYPE_COMPARISON_OP(StrongType, IntType, op)
 – NON-MEMBER COMPARISON OPERATORS ---------------------------------------—
 

Functions

template<typename StrongIndexName >
std::ostream & operations_research::operator<< (std::ostream &os, StrongIndex< StrongIndexName > arg)
 
template<typename Sink , typename... T>
void operations_research::AbslStringify (Sink &sink, StrongIndex< T... > arg)
 
template<typename StrongIntegerName >
std::ostream & operations_research::operator<< (std::ostream &os, StrongInt64< StrongIntegerName > arg)
 
template<typename Sink , typename... T>
void operations_research::AbslStringify (Sink &sink, StrongInt64< T... > arg)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongIndex, int,+)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongIndex, int, -)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongIndex, int, *)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongIndex, int, %)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t,+)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t, -)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t, *)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t,/)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t,<<)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t, > >)
 
 operations_research::STRONG_TYPE_ARITHMETIC_OP (StrongInt64, int64_t, %)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongIndex, int,==)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongIndex, int, !=)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongIndex, int,<=)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongIndex, int, >=)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongInt64, int64_t,==)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongInt64, int64_t, !=)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongInt64, int64_t,<=)
 
 operations_research::STRONG_TYPE_COMPARISON_OP (StrongInt64, int64_t, >=)
 
template<typename StrongIndexName , typename H >
operations_research::AbslHashValue (H h, const StrongIndex< StrongIndexName > &i)
 – ABSL HASHING SUPPORT --------------------------------------------------—
 
template<typename StrongIntegerName , typename H >
operations_research::AbslHashValue (H h, const StrongInt64< StrongIntegerName > &i)
 

Macro Definition Documentation

◆ DEFINE_STRONG_INDEX_TYPE

#define DEFINE_STRONG_INDEX_TYPE ( index_type_name)
Value:
struct index_type_name##_index_tag_ { \
static constexpr absl::string_view TypeName() { return #index_type_name; } \
}; \
typedef ::operations_research::StrongIndex<index_type_name##_index_tag_> \
index_type_name;

Defines the StrongIndex and typedefs it to index_type_name.

Note
The struct index_type_name ## index_tag trickery is needed to ensure that a new type is created per index_type_name.

Definition at line 71 of file strong_integers.h.

◆ DEFINE_STRONG_INT64_TYPE

#define DEFINE_STRONG_INT64_TYPE ( integer_type_name)
Value:
struct integer_type_name##_integer_tag_ { \
static constexpr absl::string_view TypeName() { \
return #integer_type_name; \
} \
}; \
typedef ::operations_research::StrongInt64<integer_type_name##_integer_tag_> \
integer_type_name;

Defines the StrongInt64 and typedefs it to integer_type_name.

Note
The struct integer_type_name ## integer_tag trickery is needed to ensure that a new type is created per integer_type_name.

Definition at line 82 of file strong_integers.h.

◆ INCREMENT_AND_DECREMENT_OPERATORS

#define INCREMENT_AND_DECREMENT_OPERATORS
Value:
ThisType& operator++() { \
++value_; \
return *this; \
} \
const ThisType operator++(int) { \
ThisType temp(*this); \
++value_; \
return temp; \
} \
ThisType& operator--() { \
--value_; \
return *this; \
} \
const ThisType operator--(int) { \
ThisType temp(*this); \
--value_; \
return temp; \
}

Definition at line 108 of file strong_integers.h.

◆ STRONG_ASSIGNMENT_OP

#define STRONG_ASSIGNMENT_OP ( StrongClass,
IntType,
op )
Value:
ThisType& operator op(const ThisType & arg_value) { \
value_ op arg_value.value(); \
return *this; \
} \
ThisType& operator op(IntType arg_value) { \
value_ op arg_value; \
return *this; \
}

--------— Implementation ---------—

Note
we need two classes as it is the only way to have different set of operators on each class.
We use to class to easily define a different set of operators for the index and int64_t type.

Definition at line 98 of file strong_integers.h.

◆ STRONG_TYPE_ARITHMETIC_OP

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

– NON-MEMBER ARITHMETIC OPERATORS ---------------------------------------—

Definition at line 272 of file strong_integers.h.

◆ STRONG_TYPE_COMPARISON_OP

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

– NON-MEMBER COMPARISON OPERATORS ---------------------------------------—

Definition at line 304 of file strong_integers.h.