Open 3D Engine AzCore API Reference  2305.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 >
< iterator > 
< const_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

 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 >
 is_integral ())
ilist end ()
ilist m_last (0)
ilist m_end (0)
ilist m_allocator (rhs.m_allocator)
 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 ()
rbegin () const
AZ_FORCE_INLINE reverse_iterator rend ()
rend () const
AZ_FORCE_INLINE const_iterator cbegin () const
AZ_FORCE_INLINE const_iterator cend () const
crbegin () const
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)

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.
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)

Public Attributes

template<class InputIterator >
 __pad0__: m_allocator(allocator) { construct_iter(first
template<class InputIterator >
template<class R , class = enable_if_t<Internal::container_compatible_range<R, value_type>>>
 __pad1__: m_allocator(alloc) { assign_range(AZStd::forward<R>(rg))
 __pad2__: vector(ilist.begin()
ilist allocator

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>
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

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

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.

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.
template<class T, class Allocator>
void AZStd::vector< T, Allocator >::resize_no_construct ( size_type  newSize)

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.

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

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

Member Data Documentation

template<class T, class Allocator>
ilist AZStd::vector< T, Allocator >::allocator
Initial value:
vector(const this_type& rhs)
size_type byteSize = sizeof(node_type) * (rhs.m_last - rhs.m_start);
if (byteSize)
m_start = reinterpret_cast<pointer>(m_allocator.allocate(byteSize, alignment_of<node_type>::value));
m_last = AZStd::uninitialized_copy(rhs.m_start, rhs.m_last, m_start, is_trivially_copy_constructible<value_type>());
m_start = 0;
m_last = 0;
vector(this_type&& rhs)
: m_start(0)

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