Google OR-Tools: ortools/base/strong_vector.h Source File
61#ifndef ORTOOLS_BASE_STRONG_VECTOR_H_
62#define ORTOOLS_BASE_STRONG_VECTOR_H_
73template <typename IntType, typename NativeType,
74 typename Alloc = std::allocator<NativeType>>
75class StrongVector : protected std::vector<NativeType, Alloc> {
77 typedef std::vector<NativeType, Alloc> ParentType;
78 typedef typename ParentType::size_type size_type;
80 typedef typename ParentType::value_type value_type;
81 typedef typename ParentType::reference reference;
83 typedef typename ParentType::pointer pointer;
85 typedef typename ParentType::iterator iterator;
113 template <typename InputIteratorType>
134 return ParentType::operator[](static_cast<size_type>(i.value()));
137 return ParentType::operator[](static_cast<size_type>(i.value()));
140 return ParentType::at(static_cast<size_type>(i.value()));
143 return ParentType::at(static_cast<size_type>(i.value()));
162 bool IsValidSize() const { return ValidSize(size()); }
167 using ParentType::capacity;
175 using ParentType::max_size;
176 using ParentType::pop_back;
179 using ParentType::shrink_to_fit;
213 void swap(StrongVector& x) noexcept { ParentType::swap(*x.mutable_get()); }
219 template <typename InputIt>
229 template <typename... Args>
231 iterator result = ParentType::emplace(pos, std::forward<Args>(args)...);
236 template <typename... Args>
238 reference value = ParentType::emplace_back(std::forward<Args>(args)...);
299 static_assert(std::is_integral<typename IntType::ValueType>::value,
300 "int type indexed vector must have integral index");
304 return H::combine(std::move(h), v.get());
309 static bool ValidSize(size_type n) {
310 return n <= std::numeric_limits<typename IntType::ValueType>::max();
314 return x.get() == y.get();
317 return x.get() != y.get();
320 return x.get() < y.get();
323 return x.get() > y.get();
326 return x.get() <= y.get();
329 return x.get() >= y.get();
friend H AbslHashValue(H h, const StrongVector &v)
Definition strong_vector.h:303
friend bool operator!=(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:316
friend void swap(StrongVector &x, StrongVector &y) noexcept
Definition strong_vector.h:331
ParentType::reference reference
Definition strong_vector.h:81
ParentType::const_reverse_iterator const_reverse_iterator
Definition strong_vector.h:88
void assign(size_type n, const value_type &val)
Definition strong_vector.h:215
value_type * data()
Definition strong_vector.h:199
std::vector< NativeType, Alloc > ParentType
Definition strong_vector.h:77
StrongVector(InputIteratorType first, InputIteratorType last, const allocator_type &a=allocator_type())
Definition strong_vector.h:114
StrongVector()
Definition strong_vector.h:91
StrongVector(size_type n, const value_type &v, const allocator_type &a=allocator_type())
Definition strong_vector.h:96
const ParentType & get() const
Definition strong_vector.h:123
void reserve(IntType n)
Definition strong_vector.h:277
void swap(StrongVector &x) noexcept
Definition strong_vector.h:213
void assign(InputIt f, InputIt l)
Definition strong_vector.h:220
StrongVector & operator=(StrongVector &&x)=default
void resize(IntType new_size)
Definition strong_vector.h:284
void resize(IntType new_size, const value_type &x)
Definition strong_vector.h:293
void push_back(const value_type &val)
Definition strong_vector.h:263
friend bool operator>=(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:328
iterator insert(const_iterator pos, value_type &&x)
Definition strong_vector.h:248
friend bool operator==(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:313
StrongVector & operator=(std::initializer_list< value_type > l)
Definition strong_vector.h:207
iterator insert(const_iterator pos, const value_type &x)
Definition strong_vector.h:243
StrongVector & operator=(const StrongVector &x)
Definition strong_vector.h:202
const value_type * data() const
Definition strong_vector.h:200
friend bool operator>(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:322
void reserve(size_type n)
Definition strong_vector.h:272
IntType start_index() const
Definition strong_vector.h:151
const_reference at(IntType i) const
Definition strong_vector.h:142
reference emplace_back(Args &&... args)
Definition strong_vector.h:237
ParentType::const_pointer const_pointer
Definition strong_vector.h:84
StrongVector(std::initializer_list< value_type > l, const allocator_type &a=allocator_type())
Definition strong_vector.h:108
const_reference operator[](IntType i) const
Definition strong_vector.h:136
bool IsValidSize() const
Definition strong_vector.h:162
ParentType::value_type value_type
Definition strong_vector.h:80
~StrongVector()
Definition strong_vector.h:119
IntType end_index() const
Definition strong_vector.h:156
StrongVector(size_type n)
Definition strong_vector.h:93
StrongVector(const allocator_type &a)
Definition strong_vector.h:92
void resize(size_type new_size)
Definition strong_vector.h:279
void resize(size_type new_size, const value_type &x)
Definition strong_vector.h:288
void assign(std::initializer_list< value_type > l)
Definition strong_vector.h:224
StrongVector(StrongVector &&x)=default
StrongVector(IntType n, const value_type &v, const allocator_type &a=allocator_type())
Definition strong_vector.h:101
friend bool operator<=(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:325
ParentType::reverse_iterator reverse_iterator
Definition strong_vector.h:87
ParentType::const_reference const_reference
Definition strong_vector.h:82
StrongVector(IntType n)
Definition strong_vector.h:94
reference operator[](IntType i)
Definition strong_vector.h:133
ParentType * mutable_get()
Definition strong_vector.h:130
iterator emplace(const_iterator pos, Args &&... args)
Definition strong_vector.h:230
ParentType::size_type size_type
Definition strong_vector.h:78
ParentType::allocator_type allocator_type
Definition strong_vector.h:79
reference at(IntType i)
Definition strong_vector.h:139
ParentType::const_iterator const_iterator
Definition strong_vector.h:86
void insert(const_iterator pos, size_type n, const value_type &x)
Definition strong_vector.h:253
StrongIntRange< IntType > index_range() const
Definition strong_vector.h:190
void insert(const_iterator pos, SIT first, SIT last)
Definition strong_vector.h:258
friend bool operator<(const StrongVector &x, const StrongVector &y)
Definition strong_vector.h:319
ParentType::pointer pointer
Definition strong_vector.h:83
void push_back(value_type &&val)
Definition strong_vector.h:267
StrongVector(const StrongVector &x)
Definition strong_vector.h:104
ParentType::iterator iterator
Definition strong_vector.h:85
Definition strong_vector.h:71