Luna::Vector
A container that stores a continuous array of elements. Elements can be added to or removed from the container dynamically.
template <typename _Ty, typename _Alloc>
class Luna::Vector
Parameters
-
_Ty
The element type of the container.
-
_Alloc
The memory allocator used by the container. If not specified, Allocator will be used.
Member functions
-
Constructs an empty vector.
-
Vector(const allocator_type &alloc)
Constructs an empty vector with an custom allocator.
-
Vector(usize count, const value_type &value, const allocator_type &alloc=allocator_type())
Constructs one vector with
count
elements, with their values initialized byvalue
. -
Vector(usize count, const allocator_type &alloc=allocator_type())
Constructs one vector with
count
elements, which their values being default-initialized. -
Constructs one vector with elements copied from the specified range.
-
Constructs a vector by copying elements from another vector.
-
Vector(const Vector &rhs, const allocator_type &alloc)
Constructs a vector with an custom allocator and with elements copied from another vector.
-
Constructs a vector by moving elements from another vector.
-
Vector(Vector &&rhs, const allocator_type &alloc)
Constructs a vector with an custom allocator and with elements moved from another vector.
-
Vector(InitializerList< value_type > init, const allocator_type &alloc=allocator_type())
Constructs one vector by coping all elements from an initializer list.
-
Vector< _Ty, _Alloc > & operator=(const Vector &rhs)
Replaces elements of the vector by coping elements from another vector.
-
Vector< _Ty, _Alloc > & operator=(Vector &&rhs)
Replaces elements of the vector by moving elements from another vector.
-
Vector< _Ty, _Alloc > & operator=(InitializerList< value_type > ilist)
Replaces elements of the vector from one initializer list.
-
Vector< _Ty, _Alloc >::iterator begin()
Gets one iterator to the first element of the vector.
-
Vector< _Ty, _Alloc >::iterator end()
Gets one iterator to the one past last element of the vector.
-
Vector< _Ty, _Alloc >::const_iterator begin() const
Gets one constant iterator to the first element of the vector.
-
Vector< _Ty, _Alloc >::const_iterator end() const
Gets one constant iterator to the one past last element of the vector.
-
Vector< _Ty, _Alloc >::const_iterator cbegin() const
Gets one constant iterator to the first element of the vector.
-
Vector< _Ty, _Alloc >::const_iterator cend() const
Gets one constant iterator to the one past last element of the vector.
-
Vector< _Ty, _Alloc >::reverse_iterator rbegin()
Gets one reverse iterator to the last element of the vector.
-
Vector< _Ty, _Alloc >::reverse_iterator rend()
Gets one reverse iterator to the one-before-first element of the vector.
-
Vector< _Ty, _Alloc >::const_reverse_iterator rbegin() const
Gets one constant reverse iterator to the last element of the vector.
-
Vector< _Ty, _Alloc >::const_reverse_iterator rend() const
Gets one constant reverse iterator to the one-before-first element of the vector.
-
Vector< _Ty, _Alloc >::const_reverse_iterator crbegin() const
Gets one constant reverse iterator to the last element of the vector.
-
Vector< _Ty, _Alloc >::const_reverse_iterator crend() const
Gets one constant reverse iterator to the one-before-first element of the vector.
-
Gets the size of the vector, that is, the number of elements in the vector.
-
Gets the capacity of the vector, that is, the maximum number of elements this vector can hold before next expansion.
-
Checks whether this vector is empty, that is, the size of this vector is
0
. -
Increases the capacity of the vector to a value greater than or equal to
new_cap
, so that it can hold at leastnew_cap
elements without reallocating the internal buffer. -
Resizes the vector.
-
void resize(usize n, const value_type &v)
Resizes the vector.
-
Reduces the capacity of the vector so that capacity == size.
-
Vector< _Ty, _Alloc >::reference operator[](usize n)
Gets the element at the specified index.
-
Vector< _Ty, _Alloc >::const_reference operator[](usize n) const
Gets the element at the specified index.
-
Vector< _Ty, _Alloc >::reference at(usize n)
Gets the element at the specified index.
-
Vector< _Ty, _Alloc >::const_reference at(usize n) const
Gets the element at the specified index.
-
Vector< _Ty, _Alloc >::reference front()
Gets the element at the front of the vector.
-
Vector< _Ty, _Alloc >::const_reference front() const
Gets the element at the front of the vector.
-
Vector< _Ty, _Alloc >::reference back()
Gets the element at the back of the vector.
-
Vector< _Ty, _Alloc >::const_reference back() const
Gets the element at the back of the vector.
-
Vector< _Ty, _Alloc >::pointer data()
Gets one pointer to the data buffer of this vector.
-
Vector< _Ty, _Alloc >::const_pointer data() const
Gets one pointer to the data buffer of this vector.
-
Removes all elements from the vector, but keeps the vector storage.
-
void push_back(const value_type &val)
Pushes one element to the back of the vector.
-
void push_back(value_type &&val)
Pushes one element to the back of the vector.
-
Removes the element from the back of the vector.
-
void assign(usize count, const value_type &value)
Replaces elements of the vector by several copies of the specified value.
-
auto assign(_InputIter first, _InputIter last) -> enable_if_t<!is_integral_v< _InputIter >, void >
Replaces elements of the vector by elements specified by one range. Elements in the range will be copy-inserted into the vector.
-
void assign(InitializerList< value_type > il)
Replaces elements of the vector by elements from one initializer vector.
-
void assign(Span< _Rty > data)
Replaces elements of the vector by elements specified by one span. Elements in the span will be copy-inserted into the vector.
-
Vector< _Ty, _Alloc >::iterator insert(const_iterator pos, const value_type &value)
Inserts the specified element to the vector.
-
Vector< _Ty, _Alloc >::iterator insert(const_iterator pos, value_type &&value)
Inserts the specified element to the vector.
-
Vector< _Ty, _Alloc >::iterator insert(const_iterator pos, usize count, const value_type &value)
Inserts several copies of the element to the vector.
-
Inserts one range of elements to the vector.
-
Vector< _Ty, _Alloc >::iterator insert(const_iterator pos, InitializerList< value_type > ilist)
Inserts one range of elements specified by the initializer list to the vector.
-
Vector< _Ty, _Alloc >::iterator insert(const_iterator pos, Span< _Rty > data)
Inserts elements specified by the span to the vector. Elements in the span will be copy-inserted into the vector.
-
Vector< _Ty, _Alloc >::iterator erase(const_iterator pos)
Removes one element from the vector.
-
Vector< _Ty, _Alloc >::iterator erase(const_iterator first, const_iterator last)
Removes one range of elements from the vector.
-
Vector< _Ty, _Alloc >::iterator swap_erase(const_iterator pos)
Destructs the element at specified posiiton, then relocates the last element of the vector to the specified position.
-
Swaps elements of this vector with the specified vector.
-
Vector< _Ty, _Alloc >::iterator emplace(const_iterator pos, _Args &&... args)
Constructs one element directly on the specified position of the vector using the provided arguments.
-
Vector< _Ty, _Alloc >::iterator emplace_back(_Args &&... args)
Constructs one element directly on the back of the vector using the provided arguments.
-
Vector< _Ty, _Alloc >::allocator_type get_allocator() const
Gets the allocator of the vector.
-
Creates one span that specifies the element buffer of this vector.
-
Span< const _Ty > span() const
Creates one constant span that specifies the element buffer of this vector.
-
Span< const _Ty > cspan() const
Creates one constant span that specifies the element buffer of this vector.