61#ifndef OR_TOOLS_BASE_STRONG_VECTOR_H_
62#define OR_TOOLS_BASE_STRONG_VECTOR_H_
73template <
typename IntType,
typename NativeType,
74 typename Alloc = std::allocator<NativeType>>
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()));
158 return IntType(
size());
165 using ParentType::back;
166 using ParentType::begin;
167 using ParentType::capacity;
168 using ParentType::cbegin;
169 using ParentType::cend;
170 using ParentType::clear;
171 using ParentType::empty;
172 using ParentType::end;
173 using ParentType::erase;
174 using ParentType::front;
175 using ParentType::max_size;
176 using ParentType::pop_back;
177 using ParentType::rbegin;
178 using ParentType::rend;
179 using ParentType::shrink_to_fit;
203 ParentType::operator=(
x.get());
208 ParentType::operator=(l);
216 DCHECK(ValidSize(n));
217 ParentType::assign(n, val);
219 template <
typename InputIt>
221 ParentType::assign(f, l);
224 void assign(std::initializer_list<value_type> l) {
225 ParentType::assign(l);
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)...);
244 iterator result = ParentType::insert(pos,
x);
249 iterator result = ParentType::insert(pos, std::move(
x));
254 ParentType::insert(pos, n,
x);
257 template <
typename SIT>
259 ParentType::insert(pos, first, last);
264 ParentType::push_back(val);
268 ParentType::push_back(std::move(val));
273 DCHECK(ValidSize(n));
274 ParentType::reserve(n);
280 DCHECK(ValidSize(new_size));
281 ParentType::resize(new_size);
289 DCHECK(ValidSize(new_size));
290 ParentType::resize(new_size,
x);
297 using ParentType::size;
299 static_assert(std::is_integral<typename IntType::ValueType>::value,
300 "int type indexed vector must have integral index");
302 template <
typename H>
304 return H::combine(std::move(h), v.
get());
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();
ParentType::reference reference
friend H AbslHashValue(H h, const StrongVector &v)
friend bool operator!=(const StrongVector &x, const StrongVector &y)
ParentType::const_iterator const_iterator
friend void swap(StrongVector &x, StrongVector &y) noexcept
void assign(size_type n, const value_type &val)
ParentType::const_reference const_reference
value_type * data()
– Pass-through methods to STL vector ----------------------------------—
StrongVector(InputIteratorType first, InputIteratorType last, const allocator_type &a=allocator_type())
StrongVector(size_type n, const value_type &v, const allocator_type &a=allocator_type())
const ParentType & get() const
void swap(StrongVector &x) noexcept
void assign(InputIt f, InputIt l)
StrongVector & operator=(StrongVector &&x)=default
void resize(IntType new_size)
void resize(IntType new_size, const value_type &x)
void push_back(const value_type &val)
friend bool operator>=(const StrongVector &x, const StrongVector &y)
iterator insert(const_iterator pos, value_type &&x)
friend bool operator==(const StrongVector &x, const StrongVector &y)
StrongVector & operator=(std::initializer_list< value_type > l)
ParentType::const_pointer const_pointer
iterator insert(const_iterator pos, const value_type &x)
StrongVector & operator=(const StrongVector &x)
ParentType::value_type value_type
const value_type * data() const
friend bool operator>(const StrongVector &x, const StrongVector &y)
void reserve(size_type n)
ParentType::allocator_type allocator_type
IntType start_index() const
– Extension methods ---------------------------------------------------—
const_reference at(IntType i) const
reference emplace_back(Args &&... args)
ParentType::iterator iterator
StrongVector(std::initializer_list< value_type > l, const allocator_type &a=allocator_type())
const_reference operator[](IntType i) const
bool IsValidSize() const
Returns true if the vector is fully addressable by the index type.
IntType end_index() const
ParentType::reverse_iterator reverse_iterator
StrongVector(size_type n)
std::vector< NativeType, Alloc > ParentType
StrongVector(const allocator_type &a)
ParentType::const_reverse_iterator const_reverse_iterator
void resize(size_type new_size)
void resize(size_type new_size, const value_type &x)
void assign(std::initializer_list< value_type > l)
StrongVector(StrongVector &&x)=default
StrongVector(IntType n, const value_type &v, const allocator_type &a=allocator_type())
friend bool operator<=(const StrongVector &x, const StrongVector &y)
ParentType::size_type size_type
reference operator[](IntType i)
– Modified methods ----------------------------------------------------—
ParentType * mutable_get()
iterator emplace(const_iterator pos, Args &&... args)
void insert(const_iterator pos, size_type n, const value_type &x)
ParentType::pointer pointer
StrongIntRange< IntType > index_range() const
void insert(const_iterator pos, SIT first, SIT last)
friend bool operator<(const StrongVector &x, const StrongVector &y)
void push_back(value_type &&val)
StrongVector(const StrongVector &x)