Open 3D Engine AzCore API Reference  2205.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
AZStd::vector< T, Allocator > Class Template Reference

#include <vector.h>

Public Types

typedef T * pointer
typedef T & reference
typedef Allocator::difference_type difference_type
typedef Allocator::size_type size_type
typedef pointer iterator_impl
typedef const_pointer const_iterator_impl
typedef iterator_impl iterator
typedef const_iterator_impl const_iterator
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

 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 (const InputIterator &first, const InputIterator &last)
template<class InputIterator >
 vector (const InputIterator &first, const InputIterator &last, const allocator_type &allocator)
 vector (std::initializer_list< T > list, 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)
iterator insert (const_iterator pos, value_type &&value)
template<class ... Args>
iterator emplace (const_iterator pos, Args &&... args)
void swap (this_type &&rhs)
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)
iterator insert (const_iterator insertPos, const_reference value)
void insert (const_iterator insertPos, size_type numElements, const_reference value)
template<class InputIterator >
AZ_FORCE_INLINE void insert (const_iterator insertPos, const InputIterator &first, const InputIterator &last)
AZ_FORCE_INLINE void insert (const_iterator insertPos, std::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.
const AZ_FORCE_INLINE 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
void push_back ()
AZ_FORCE_INLINE void leak_and_reset ()
void set_capacity (size_type numElements)

Public Attributes

const typedef T * const_pointer
const typedef T & const_reference

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

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.

◆ push_back()

template<class T , class Allocator = AZStd::allocator>
void AZStd::vector< T, Allocator >::push_back ( )

Pushes an element at the end of the vector without a provided instance. This can be used for value types with expensive constructors so we don't want to create temporary one.

◆ resize_no_construct()

template<class T , class Allocator = AZStd::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.

◆ set_capacity()

template<class T , class Allocator = AZStd::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.

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