Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZStd::vector< T, Allocator > Class Template Reference

#include <vector.h>

Public Types

typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef pointer iterator_impl
 
typedef const_pointer const_iterator_impl
 
typedef iterator_impl iterator
 
typedef const_iterator_impl const_iterator
 
using difference_type = iter_difference_t< iterator >
 
using size_type = make_unsigned_t< difference_type >
 
typedef AZStd::reverse_iterator< iterator > reverse_iterator
 
typedef AZStd::reverse_iterator< const_iterator > const_reverse_iterator
 
typedef T value_type
 
typedef Allocator allocator_type
 
typedef value_type node_type
 Allocation node type. Common for all AZStd containers. In vectors case we allocate always "sizeof(node_type)*capacity" block.
 

Public Member Functions

AZ_FORCE_INLINE vector ()
 Construct an empty vector.
 
AZ_FORCE_INLINE vector (const allocator_type &allocator)
 
 vector (size_type numElements)
 
 vector (size_type numElements, const_reference value)
 
 vector (size_type numElements, const_reference value, const allocator_type &allocator)
 
template<class InputIterator >
 vector (InputIterator first, InputIterator last, const allocator_type &allocator=allocator_type())
 
template<class R , class = enable_if_t<Internal::container_compatible_range<R, value_type>>>
 vector (from_range_t, R &&rg, const allocator_type &alloc=Allocator())
 
 vector (initializer_list< T > ilist, const allocator_type &allocator=allocator_type())
 
 vector (const this_type &rhs)
 
 vector (this_type &&rhs)
 
 vector (this_type &&rhs, const allocator_type &allocator)
 
this_typeoperator= (this_type &&rhs)
 
void assign_rv (this_type &&rhs)
 
void push_back (value_type &&value)
 
template<class ... Args>
reference emplace_back (Args &&... args)
 
template<class R >
auto append_range (R &&rg) -> enable_if_t< Internal::container_compatible_range< R, T > >
 
iterator insert (const_iterator pos, value_type &&value)
 
template<class ... Args>
iterator emplace (const_iterator pos, Args &&... args)
 
this_typeoperator= (const this_type &rhs)
 
AZ_FORCE_INLINE size_type size () const
 
AZ_FORCE_INLINE size_type max_size () const
 
AZ_FORCE_INLINE bool empty () const
 
void reserve (size_type numElements)
 
void shrink_to_fit ()
 
AZ_FORCE_INLINE size_type capacity () const
 
AZ_FORCE_INLINE iterator begin ()
 
AZ_FORCE_INLINE const_iterator begin () const
 
AZ_FORCE_INLINE iterator end ()
 
AZ_FORCE_INLINE const_iterator end () const
 
AZ_FORCE_INLINE reverse_iterator rbegin ()
 
AZ_FORCE_INLINE const_reverse_iterator rbegin () const
 
AZ_FORCE_INLINE reverse_iterator rend ()
 
AZ_FORCE_INLINE const_reverse_iterator rend () const
 
AZ_FORCE_INLINE const_iterator cbegin () const
 
AZ_FORCE_INLINE const_iterator cend () const
 
AZ_FORCE_INLINE const_reverse_iterator crbegin () const
 
AZ_FORCE_INLINE const_reverse_iterator crend () const
 
AZ_FORCE_INLINE void resize (size_type newSize)
 
void resize_no_construct (size_type newSize)
 
AZ_FORCE_INLINE void resize (size_type newSize, const_reference value)
 
AZ_FORCE_INLINE reference at (size_type position)
 
AZ_FORCE_INLINE const_reference at (size_type position) const
 
AZ_FORCE_INLINE reference operator[] (size_type position)
 
AZ_FORCE_INLINE const_reference operator[] (size_type position) const
 
AZ_FORCE_INLINE reference front ()
 
AZ_FORCE_INLINE const_reference front () const
 
AZ_FORCE_INLINE reference back ()
 
AZ_FORCE_INLINE const_reference back () const
 
void push_back (const_reference value)
 
void pop_back ()
 
void assign (size_type numElements, const_reference value)
 
template<class InputIterator >
AZ_FORCE_INLINE void assign (const InputIterator &first, const InputIterator &last)
 
template<class R >
auto assign_range (R &&rg) -> enable_if_t< Internal::container_compatible_range< R, value_type > >
 
void assign (initializer_list< T > iList)
 
iterator insert (const_iterator insertPos, const_reference value)
 
iterator insert (const_iterator insertPos, size_type numElements, const_reference value)
 
template<class InputIterator >
iterator insert (const_iterator insertPos, InputIterator first, InputIterator last)
 
template<class R >
auto insert_range (const_iterator insertPos, R &&rg) -> enable_if_t< Internal::container_compatible_range< R, value_type >, iterator >
 
iterator insert (const_iterator insertPos, initializer_list< T > ilist)
 
iterator erase (const_iterator elementIter)
 
iterator erase (const_iterator first, const_iterator last)
 
AZ_FORCE_INLINE void clear ()
 
AZ_INLINE void swap (this_type &rhs)
 
Extensions

AZ_FORCE_INLINE pointer data ()
 TR1 Extension. Return pointer to the vector data. The vector data is guaranteed to be stored as an array.
 
AZ_FORCE_INLINE const_pointer data () const
 
AZ_FORCE_INLINE allocator_type & get_allocator ()
 The only difference from the standard is that we return the allocator instance, not a copy.
 
AZ_FORCE_INLINE const allocator_type & get_allocator () const
 
void set_allocator (const allocator_type &allocator)
 Set the vector allocator. If different than then current all elements will be reallocated.
 
AZ_FORCE_INLINE bool validate () const
 
AZ_FORCE_INLINE int validate_iterator (const const_iterator &iter) const
 Validates an iter iterator. Returns a combination of iterator_status_flag.
 
AZ_FORCE_INLINE int validate_iterator (const const_reverse_iterator &iter) const
 
AZ_FORCE_INLINE void leak_and_reset ()
 
void set_capacity (size_type numElements)
 

Protected Attributes

pointer m_start {}
 Pointer to the first allocated element of the array.
 
pointer m_last {}
 Pointer after the last used element.
 
pointer m_end {}
 Pointer after the last allocated element.
 
allocator_type m_allocator
 Instance of the allocator.
 

Detailed Description

template<class T, class Allocator = AZStd::allocator>
class AZStd::vector< T, Allocator >

The vector container (AKA dynamic array) is complaint with CStd (23.2.4). In addition we introduce the following extensions.

The vector keeps all elements in a single memory block. When it grows it reallocated all elements. The rule for growing is that we allocate every time the 50% more memory then then current number of elements. This way to insert ~1000 elements 1 by 1 it will take 17 allocations. Of course if you know that in advance it will be smart to set the capacity in advance, this way you will have only 1 allocation AZStdExamples. When you need a vector with preset capacity use fixed_vector.

Member Function Documentation

◆ leak_and_reset()

template<class T , class Allocator = AZStd::allocator>
AZ_FORCE_INLINE void AZStd::vector< T, Allocator >::leak_and_reset ( )
inline

Resets the container without deallocating any memory or calling any destructor. This function should be used when we need very quick tear down. Generally it's used for temporary vectors and we can just nuke them that way. In addition the provided Allocators, has leak and reset flag which will enable automatically this behavior. So this function should be used in special cases AZStdExamples.

Note
This function is added to the vector for consistency. In the vector case we have only one allocation, and if the allocator allows memory leaks it can just leave deallocate function empty, which performance wise will be the same. For more complex containers this will make big difference.

◆ resize_no_construct()

template<class T , class Allocator = AZStd::allocator>
void AZStd::vector< T, Allocator >::resize_no_construct ( size_type  newSize)
inline

Extension it will set the increase size without calling default constructors. This is provided so we can use the vector as a generic buffer where we don't have to pay the cost of elements that we will construct over.

◆ set_capacity()

template<class T , class Allocator = AZStd::allocator>
void AZStd::vector< T, Allocator >::set_capacity ( size_type  numElements)
inline

Set the capacity of the vector, if necessary it will destroy elements at the end of the container to match the new capacity.


The documentation for this class was generated from the following files: