SuperDex Physics C++ API
Loading...
Searching...
No Matches
superdex::DynamicArray< T > Class Template Reference

A dynamically resizable array with syntax and behavior similar to std::pmr::vector. More...

#include <dynamic_array.h>

Public Types

using const_iterator = T const*
using iterator = T*
using size_type = size_t
using value_type = T

Public Member Functions

template<class InputContainerT>
void append (InputContainerT const &container)
 Add values to the end of this DynamicArray by copying them from another iterable container.
template<class InputIt>
void append (InputIt rangeBegin, InputIt rangeEnd)
 Add values to the end of this DynamicArray by copying them from the half-open range [rangeBegin, rangeEnd).
template<typename InputIt, std::enable_if_t<(std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits< InputIt >::iterator_category >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
void assign (InputIt rangeBegin, InputIt rangeEnd)
 Replace the contents of this DynamicArray by copying values from the half-open range [rangeBegin, rangeEnd).
T & back ()
 Get a reference to the last element.
T const & back () const
 Get a const reference to the last element.
iterator begin ()
 Get an iterator pointing to the beginning of the array.
const_iterator begin () const
 Get a const iterator pointing to the beginning of the array.
size_type capacity () const
 Get the number of elements that could fit in the array without allocating more memory.
const_iterator cbegin () const
 Get a const iterator pointing to the beginning of the array.
const_iterator cend () const
 Get a const iterator pointing to the next element AFTER the end of the array.
void clear ()
 Set the size to zero.
T * data ()
 Get a pointer to the first element.
T const * data () const
 Get a const pointer to the first element.
 DynamicArray ()=default
 Construct an empty DynamicArray with the default allocator.
 DynamicArray (Allocator *allocator)
 Construct an empty DynamicArray with a specific allocator.
 DynamicArray (DynamicArray &&other) noexcept
 Move construct from another DynamicArray.
 DynamicArray (DynamicArray &&other, Allocator *allocator)
 Construct a DynamicArray by moving memory or values from another one.
 DynamicArray (DynamicArray const &other)
 Copy construct from another DynamicArray.
 DynamicArray (DynamicArray const &other, Allocator *allocator)
 Construct a DynamicArray and copy values from another one.
template<typename InputContainerT, std::enable_if_t<(!std::is_same_v< std::decay_t< InputContainerT >, DynamicArray > &&sizeof(decltype(std::begin(std::declval< InputContainerT const & >()))) &&sizeof(decltype(std::end(std::declval< InputContainerT const & >())))), superdex::ConceptMatch > = superdex::ConceptMatch::True>
 DynamicArray (InputContainerT const &other, Allocator *allocator=GetDefaultAllocator())
 Construct a DynamicArray and copy values from another iterable container type like superdex::Span, std::vector, std::list, etc...
template<typename InputIt, std::enable_if_t<(std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits< InputIt >::iterator_category >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
 DynamicArray (InputIt rangeBegin, InputIt rangeEnd, Allocator *allocator=GetDefaultAllocator())
 Construct a DynamicArray and copy values from the half-open range: [rangeBegin, rangeEnd).
 DynamicArray (size_type size, Allocator *allocator=GetDefaultAllocator())
 Construct a DynamicArray with an initial size.
template<typename FromT, std::enable_if_t<(std::is_convertible_v< FromT, T >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
 DynamicArray (size_type size, FromT const &defaultValue, Allocator *allocator=GetDefaultAllocator())
 Construct a DynamicArray filled with copies of the specified value.
 DynamicArray (std::initializer_list< T > const &list, Allocator *allocator=GetDefaultAllocator())
 Construct a DynamicArray and copy values from a std::initializer_list.
template<class... Args>
void emplace_back (Args &&... args)
 Emplace a new element at the end of the array.
bool empty () const
 Return true if the array is empty (zero size).
iterator end ()
 Get an iterator pointing to the next element AFTER the end of the array.
const_iterator end () const
 Get a const iterator pointing to the next element AFTER the end of the array.
void erase (const_iterator it_)
 Remove one element from this array.
void erase (const_iterator rangeBegin_, const_iterator rangeEnd_)
 Remove the half-open range [rangeBegin, rangeEnd) from this array.
void erase_unordered (iterator it)
 Remove one element from this array and swap the last element into its place.
T & front ()
 Get a reference to the first element.
T const & front () const
 Get a const reference to the first element.
Allocatorget_allocator () const
 Get a pointer to the polymorphic allocator.
bool operator!= (DynamicArray const &other) const
 Comparison returns false unless the other array has the same size and all values are equal.
DynamicArrayoperator= (DynamicArray &&other)
 Move Assignment: Replace the contents of this DynamicArray by moving memory or values from another one.
DynamicArrayoperator= (DynamicArray const &other)
 Copy Assignment: Replace the contents of this DynamicArray by copying values from another one.
template<typename InputContainerT, std::enable_if_t<(!std::is_same_v< std::decay_t< InputContainerT >, DynamicArray > &&sizeof(decltype(std::begin(std::declval< InputContainerT const & >()))) &&sizeof(decltype(std::end(std::declval< InputContainerT const & >())))), superdex::ConceptMatch > = superdex::ConceptMatch::True>
DynamicArrayoperator= (InputContainerT const &other)
 Copy Assignment: Replace the contents of this DynamicArray by copying values from another iterable container of compatible type.
DynamicArrayoperator= (std::initializer_list< T > const &list)
 Copy Assignment: Replace the contents of this DynamicArray by copying values from a std::initializer_list.
bool operator== (DynamicArray const &other) const
 Comparison returns true if the other array has the same size and all values are equal.
T & operator[] (size_type i)
 Get a reference to the value at index i.
T const & operator[] (size_type i) const
 Get a reference to the value at index i.
void pop_back ()
 Remove the last element of the array (must not be empty).
T & push_back ()
 Default construct a new element at the end of the array.
void push_back (T &&value)
 Move the value to a new element at the end of the array.
void push_back (T const &value)
 Copy the value to a new element at the end of the array.
void reserve (size_type newCapacity)
 Ensure that this array has at least the specified capacity.
template<typename... Args>
void reset (Args &&... args)
 Reset the state of this DynamicArray using the arguments from any constructor.
void resize (size_type newSize)
 Set the size.
void resize (size_type newSize, T const &value)
 Set the size.
void resize_noinit (size_type newSize)
 Set the size but do not initialize any new elements.
void shrink_to_fit ()
 Ensure that the capacity (memory allocated) is no larger than the size (memory used).
size_type size () const
 Get the number of elements in the array.
 ~DynamicArray ()
 Destroy the DynamicArray object and all of its elements.

Detailed Description

template<class T>
class superdex::DynamicArray< T >

A dynamically resizable array with syntax and behavior similar to std::pmr::vector.

Remarks
  • Optionally provide your own polymorphic allocator.
  • Compatible with FILO allocators as long as you reserve or resize sufficient memory.
  • Extends the std::pmr::vector syntax with new methods including resize_noinit and append.
Warning
DynamicArray does not provide equivalent exception safety guarantees as std::vector. Exception-safe use assumes that element construction, assignment, destruction, move operations, and allocator operations do not throw. For example:
  • Reallocation via emplace_back, push_back, append, assign, reserve, resize, or shrink_to_fit can leak memory or leave the array in an invalid state if T's move constructor throws.
  • Construction, append, assign, and resize can leak memory or leave the array in an invalid state if T's constructors or assignment operators throw.
  • Moving from a DynamicArray with a different allocator does not provide the same rollback or cleanup guarantees as std::vector if moving elements throws.
  • Allocator exceptions may leave the array in an invalid state in code paths that release old storage before allocating new storage.
Template Parameters
TElement value type.

Definition at line 105 of file dynamic_array.h.

Member Typedef Documentation

◆ const_iterator

template<class T>
using superdex::DynamicArray< T >::const_iterator = T const*

Definition at line 111 of file dynamic_array.h.

◆ iterator

template<class T>
using superdex::DynamicArray< T >::iterator = T*

Definition at line 112 of file dynamic_array.h.

◆ size_type

template<class T>
using superdex::DynamicArray< T >::size_type = size_t

Definition at line 114 of file dynamic_array.h.

◆ value_type

template<class T>
using superdex::DynamicArray< T >::value_type = T

Definition at line 113 of file dynamic_array.h.

Constructor & Destructor Documentation

◆ DynamicArray() [1/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( )
default

Construct an empty DynamicArray with the default allocator.

◆ DynamicArray() [2/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( Allocator * allocator)
inlineexplicit

Construct an empty DynamicArray with a specific allocator.

Parameters
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 126 of file dynamic_array.h.

◆ DynamicArray() [3/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( size_type size,
Allocator * allocator = GetDefaultAllocator() )
inlineexplicit

Construct a DynamicArray with an initial size.

All elements will be default constructed or zero-initialized (for POD types).

Parameters
sizeInitial size (number of elements, not bytes)
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 135 of file dynamic_array.h.

◆ DynamicArray() [4/11]

template<class T>
template<typename FromT, std::enable_if_t<(std::is_convertible_v< FromT, T >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
superdex::DynamicArray< T >::DynamicArray ( size_type size,
FromT const & defaultValue,
Allocator * allocator = GetDefaultAllocator() )
inline

Construct a DynamicArray filled with copies of the specified value.

Template Parameters
FromTInput value type. Must be same or convertible to type T.
Parameters
sizeInitial size (number of elements, not bytes)
defaultValueValue to copy to all new array elements.
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 152 of file dynamic_array.h.

◆ DynamicArray() [5/11]

template<class T>
template<typename InputIt, std::enable_if_t<(std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits< InputIt >::iterator_category >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
superdex::DynamicArray< T >::DynamicArray ( InputIt rangeBegin,
InputIt rangeEnd,
Allocator * allocator = GetDefaultAllocator() )
inline

Construct a DynamicArray and copy values from the half-open range: [rangeBegin, rangeEnd).

Template Parameters
InputItInput forward iterator type (typically deduced).
Parameters
rangeBeginIterator pointing to the first input value to copy.
rangeEndIterator pointing ONE PAST the last input value to copy.
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 177 of file dynamic_array.h.

◆ DynamicArray() [6/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( std::initializer_list< T > const & list,
Allocator * allocator = GetDefaultAllocator() )
inline

Construct a DynamicArray and copy values from a std::initializer_list.

Parameters
listList from which values will be copied.
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 192 of file dynamic_array.h.

◆ DynamicArray() [7/11]

template<class T>
template<typename InputContainerT, std::enable_if_t<(!std::is_same_v< std::decay_t< InputContainerT >, DynamicArray > &&sizeof(decltype(std::begin(std::declval< InputContainerT const & >()))) &&sizeof(decltype(std::end(std::declval< InputContainerT const & >())))), superdex::ConceptMatch > = superdex::ConceptMatch::True>
superdex::DynamicArray< T >::DynamicArray ( InputContainerT const & other,
Allocator * allocator = GetDefaultAllocator() )
inlineexplicit

Construct a DynamicArray and copy values from another iterable container type like superdex::Span, std::vector, std::list, etc...

Template Parameters
InputContainerTInput container type. Must support std::begin and std::end.
Parameters
otherContainer from which values will be copied.
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 209 of file dynamic_array.h.

◆ DynamicArray() [8/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( DynamicArray< T > const & other,
Allocator * allocator )
inline

Construct a DynamicArray and copy values from another one.

Parameters
otherAnother DynamicArray from which values will be copied.
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 218 of file dynamic_array.h.

◆ DynamicArray() [9/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( DynamicArray< T > const & other)
inline

Copy construct from another DynamicArray.

Use the same allocator.

Parameters
otherAnother DynamicArray from which the allocator and the values will be copied.

Definition at line 226 of file dynamic_array.h.

◆ DynamicArray() [10/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( DynamicArray< T > && other,
Allocator * allocator )
inline

Construct a DynamicArray by moving memory or values from another one.

Remarks
If the allocators are equal, then array memory ownership will be transferred from the other array to this one. Otherwise, new memory will be allocated for this array and then the other array's values will be moved into it. Either way, the other array will be empty after this call.
Parameters
otherAnother DynamicArray from which memory or values will be moved
allocatorPointer to a polymorphic allocator. Must outlive this DynamicArray object.

Definition at line 240 of file dynamic_array.h.

◆ DynamicArray() [11/11]

template<class T>
superdex::DynamicArray< T >::DynamicArray ( DynamicArray< T > && other)
inlinenoexcept

Move construct from another DynamicArray.

Use the same allocator.

Remarks
Memory ownership is always transferred. No new allocation.
Parameters
otherAnother DynamicArray from which memory will be moved. Will be empty after this call.

Definition at line 269 of file dynamic_array.h.

◆ ~DynamicArray()

template<class T>
superdex::DynamicArray< T >::~DynamicArray ( )
inline

Destroy the DynamicArray object and all of its elements.

Deallocate any memory that was used.

Definition at line 281 of file dynamic_array.h.

Member Function Documentation

◆ append() [1/2]

template<class T>
template<class InputContainerT>
void superdex::DynamicArray< T >::append ( InputContainerT const & container)
inline

Add values to the end of this DynamicArray by copying them from another iterable container.

Warning
It is illegal to append a DynamicArray to itself.
Template Parameters
InputContainerTAnother iterable container type. Must support std::begin and std::end.
Parameters
containerContainer from which value will be copied.

Definition at line 823 of file dynamic_array.h.

◆ append() [2/2]

template<class T>
template<class InputIt>
void superdex::DynamicArray< T >::append ( InputIt rangeBegin,
InputIt rangeEnd )
inline

Add values to the end of this DynamicArray by copying them from the half-open range [rangeBegin, rangeEnd).

Warning
The iterators are not allowed to point to elements within this same DynamicArray. Consider appending a copy of the elements instead.
Template Parameters
InputItInput iterator type (typically deduced).
Parameters
rangeBeginIterator pointing to the first input value to copy.
rangeEndIterator pointing ONE PAST the last input value to copy.

Definition at line 795 of file dynamic_array.h.

◆ assign()

template<class T>
template<typename InputIt, std::enable_if_t<(std::is_base_of_v< std::input_iterator_tag, typename std::iterator_traits< InputIt >::iterator_category >), superdex::ConceptMatch > = superdex::ConceptMatch::True>
void superdex::DynamicArray< T >::assign ( InputIt rangeBegin,
InputIt rangeEnd )
inline

Replace the contents of this DynamicArray by copying values from the half-open range [rangeBegin, rangeEnd).

Warning
The iterators are not allowed to point to elements within this same DynamicArray.
Template Parameters
InputItInput iterator type (typically deduced).
Parameters
rangeBeginIterator pointing to the first value to copy from.
rangeEndIterator pointing ONE PAST the last value to copy from.

Definition at line 720 of file dynamic_array.h.

◆ back() [1/2]

template<class T>
T & superdex::DynamicArray< T >::back ( )
inlinenodiscard

Get a reference to the last element.

Array must not be empty.

Definition at line 353 of file dynamic_array.h.

◆ back() [2/2]

template<class T>
T const & superdex::DynamicArray< T >::back ( ) const
inlinenodiscard

Get a const reference to the last element.

Array must not be empty.

Definition at line 361 of file dynamic_array.h.

◆ begin() [1/2]

template<class T>
iterator superdex::DynamicArray< T >::begin ( )
inlinenodiscard

Get an iterator pointing to the beginning of the array.

Definition at line 295 of file dynamic_array.h.

◆ begin() [2/2]

template<class T>
const_iterator superdex::DynamicArray< T >::begin ( ) const
inlinenodiscard

Get a const iterator pointing to the beginning of the array.

Definition at line 302 of file dynamic_array.h.

◆ capacity()

template<class T>
size_type superdex::DynamicArray< T >::capacity ( ) const
inlinenodiscard

Get the number of elements that could fit in the array without allocating more memory.

Definition at line 390 of file dynamic_array.h.

◆ cbegin()

template<class T>
const_iterator superdex::DynamicArray< T >::cbegin ( ) const
inlinenodiscard

Get a const iterator pointing to the beginning of the array.

Definition at line 309 of file dynamic_array.h.

◆ cend()

template<class T>
const_iterator superdex::DynamicArray< T >::cend ( ) const
inlinenodiscard

Get a const iterator pointing to the next element AFTER the end of the array.

Definition at line 330 of file dynamic_array.h.

◆ clear()

template<class T>
void superdex::DynamicArray< T >::clear ( )
inline

Set the size to zero.

Does not deallocate memory.

See also
shrink_to_fit

Definition at line 512 of file dynamic_array.h.

◆ data() [1/2]

template<class T>
T * superdex::DynamicArray< T >::data ( )
inlinenodiscard

Get a pointer to the first element.

May be nullptr if this array is empty.

Definition at line 369 of file dynamic_array.h.

◆ data() [2/2]

template<class T>
T const * superdex::DynamicArray< T >::data ( ) const
inlinenodiscard

Get a const pointer to the first element.

May be nullptr if this array is empty.

Definition at line 376 of file dynamic_array.h.

◆ emplace_back()

template<class T>
template<class... Args>
void superdex::DynamicArray< T >::emplace_back ( Args &&... args)
inline

Emplace a new element at the end of the array.

Remarks
If people use reserve or resize, then we will allocate the exact capacity requested. However, if people call push_back or emplace_back repeatedly, we will grow the capacity by 50% each time more memory is needed. This achieves amortized O(1) cost, similar to std::vector.

Unlike std::vector, we skip past the first few reallocations by reserving a capacity of kGrowthPatternStartSize the first time. See GetNextCapacity() for details.

Warning
The argument is not allowed to be a reference to an element within this same DynamicArray. In that case, consider emplacing a copy of the element instead.
Template Parameters
ArgsAny types that can be passed to type T's constructor.
Parameters
argsAny arguments that can be passed to type T's constructor.

Definition at line 554 of file dynamic_array.h.

◆ empty()

template<class T>
bool superdex::DynamicArray< T >::empty ( ) const
inlinenodiscard

Return true if the array is empty (zero size).

Definition at line 397 of file dynamic_array.h.

◆ end() [1/2]

template<class T>
iterator superdex::DynamicArray< T >::end ( )
inlinenodiscard

Get an iterator pointing to the next element AFTER the end of the array.

Definition at line 316 of file dynamic_array.h.

◆ end() [2/2]

template<class T>
const_iterator superdex::DynamicArray< T >::end ( ) const
inlinenodiscard

Get a const iterator pointing to the next element AFTER the end of the array.

Definition at line 323 of file dynamic_array.h.

◆ erase() [1/2]

template<class T>
void superdex::DynamicArray< T >::erase ( const_iterator it_)
inline

Remove one element from this array.

Any later elements will be shifted down to preserve order.

Parameters
it_Iterator pointing to the element to remove.

Definition at line 676 of file dynamic_array.h.

◆ erase() [2/2]

template<class T>
void superdex::DynamicArray< T >::erase ( const_iterator rangeBegin_,
const_iterator rangeEnd_ )
inline

Remove the half-open range [rangeBegin, rangeEnd) from this array.

Any later elements will be shifted down to preserve order.

Remarks
Size will be reduced by (rangeEnd - rangeBegin).
Parameters
rangeBegin_Iterator pointing to the first element to remove.
rangeEnd_Iterator pointing ONE PAST the last element to remove.

Definition at line 640 of file dynamic_array.h.

◆ erase_unordered()

template<class T>
void superdex::DynamicArray< T >::erase_unordered ( iterator it)
inline

Remove one element from this array and swap the last element into its place.

This achieves O(1) cost but does not preserve order.

Parameters
itIterator pointing to the element to remove.

Definition at line 695 of file dynamic_array.h.

◆ front() [1/2]

template<class T>
T & superdex::DynamicArray< T >::front ( )
inlinenodiscard

Get a reference to the first element.

Array must not be empty.

Definition at line 337 of file dynamic_array.h.

◆ front() [2/2]

template<class T>
T const & superdex::DynamicArray< T >::front ( ) const
inlinenodiscard

Get a const reference to the first element.

Array must not be empty.

Definition at line 345 of file dynamic_array.h.

◆ get_allocator()

template<class T>
Allocator * superdex::DynamicArray< T >::get_allocator ( ) const
inlinenodiscard

Get a pointer to the polymorphic allocator.

Definition at line 830 of file dynamic_array.h.

◆ operator!=()

template<class T>
bool superdex::DynamicArray< T >::operator!= ( DynamicArray< T > const & other) const
inline

Comparison returns false unless the other array has the same size and all values are equal.

Definition at line 965 of file dynamic_array.h.

◆ operator=() [1/4]

template<class T>
DynamicArray & superdex::DynamicArray< T >::operator= ( DynamicArray< T > && other)
inline

Move Assignment: Replace the contents of this DynamicArray by moving memory or values from another one.

Remarks
If the allocators are equal, then array memory ownership will be transferred from the other array to this one. Otherwise, new memory will be allocated for this array (if necessary) and then the other array's values will be moved into it. Either way, the other array will be empty after this call.
Parameters
otherAnother DynamicArray from which memory or values will be moved.
Returns
*this

Definition at line 877 of file dynamic_array.h.

◆ operator=() [2/4]

template<class T>
DynamicArray & superdex::DynamicArray< T >::operator= ( DynamicArray< T > const & other)
inline

Copy Assignment: Replace the contents of this DynamicArray by copying values from another one.

Parameters
otherAnother DynamicArray from which values will be copied.
Returns
*this

Definition at line 857 of file dynamic_array.h.

◆ operator=() [3/4]

template<class T>
template<typename InputContainerT, std::enable_if_t<(!std::is_same_v< std::decay_t< InputContainerT >, DynamicArray > &&sizeof(decltype(std::begin(std::declval< InputContainerT const & >()))) &&sizeof(decltype(std::end(std::declval< InputContainerT const & >())))), superdex::ConceptMatch > = superdex::ConceptMatch::True>
DynamicArray & superdex::DynamicArray< T >::operator= ( InputContainerT const & other)
inline

Copy Assignment: Replace the contents of this DynamicArray by copying values from another iterable container of compatible type.

Template Parameters
InputContainerTAnother container type. Must support std::begin and std::end.
Parameters
otherContainer from which values will be copied.
Returns
*this

Definition at line 939 of file dynamic_array.h.

◆ operator=() [4/4]

template<class T>
DynamicArray & superdex::DynamicArray< T >::operator= ( std::initializer_list< T > const & list)
inline

Copy Assignment: Replace the contents of this DynamicArray by copying values from a std::initializer_list.

Parameters
listList of values to copy
Returns
*this

Definition at line 920 of file dynamic_array.h.

◆ operator==()

template<class T>
bool superdex::DynamicArray< T >::operator== ( DynamicArray< T > const & other) const
inline

Comparison returns true if the other array has the same size and all values are equal.

Definition at line 947 of file dynamic_array.h.

◆ operator[]() [1/2]

template<class T>
T & superdex::DynamicArray< T >::operator[] ( size_type i)
inlinenodiscard

Get a reference to the value at index i.

Definition at line 837 of file dynamic_array.h.

◆ operator[]() [2/2]

template<class T>
T const & superdex::DynamicArray< T >::operator[] ( size_type i) const
inlinenodiscard

Get a reference to the value at index i.

Definition at line 845 of file dynamic_array.h.

◆ pop_back()

template<class T>
void superdex::DynamicArray< T >::pop_back ( )
inline

Remove the last element of the array (must not be empty).

Definition at line 623 of file dynamic_array.h.

◆ push_back() [1/3]

template<class T>
T & superdex::DynamicArray< T >::push_back ( )
inline

Default construct a new element at the end of the array.

Remarks
May over allocate to achieve amortized O(1) cost like emplace_back.
auto& obj = myArray.push_back();
obj.value = someValue;
Returns
T& A reference to the new element

Definition at line 615 of file dynamic_array.h.

◆ push_back() [2/3]

template<class T>
void superdex::DynamicArray< T >::push_back ( T && value)
inline

Move the value to a new element at the end of the array.

Remarks
May over allocate to achieve amortized O(1) cost like emplace_back.
Warning
The argument is not allowed to be a reference to an element within this same DynamicArray. In that case, consider pushing a copy of the element instead.
Parameters
valueValue to be moved
See also
emplace_back

Definition at line 600 of file dynamic_array.h.

◆ push_back() [3/3]

template<class T>
void superdex::DynamicArray< T >::push_back ( T const & value)
inline

Copy the value to a new element at the end of the array.

Remarks
May over allocate to achieve amortized O(1) cost like emplace_back.
Warning
The argument is not allowed to be a reference to an element within this same DynamicArray. In that case, consider pushing a copy of the element instead.
Parameters
valueValue to be copied
See also
emplace_back

Definition at line 585 of file dynamic_array.h.

◆ reserve()

template<class T>
void superdex::DynamicArray< T >::reserve ( size_type newCapacity)
inline

Ensure that this array has at least the specified capacity.

Parameters
newCapacityDesired capacity measured by number of elements (not bytes).
Warning
If you call reserve repeatedly with incrementally larger values, it will reallocate the memory every time. It will not overallocate the memory the way emplace_back does.

Definition at line 502 of file dynamic_array.h.

◆ reset()

template<class T>
template<typename... Args>
void superdex::DynamicArray< T >::reset ( Args &&... args)
inline

Reset the state of this DynamicArray using the arguments from any constructor.

Any previous elements will be destroyed. Any previous memory will be deallocated.

Remarks
This method can be used to assign a new allocator pointer to a DynamicArray object that has already been constructed (unlike move assignment, which does not move the allocator).
Template Parameters
ArgsAny argument types supported by one of the DynamicArray constructors.
Parameters
argsAny parameter types supported by one of the DynamicArray constructors.

Definition at line 489 of file dynamic_array.h.

◆ resize() [1/2]

template<class T>
void superdex::DynamicArray< T >::resize ( size_type newSize)
inline

Set the size.

If larger than the current size, new elements will be default constructed (zero-initialized for POD types).

Parameters
newSizeNew number of elements
Remarks
The first time you call resize, capacity will be allocated for the exact size requested. However, subsequent calls to resize may allocate more than requested, similar to emplace_back.

Definition at line 411 of file dynamic_array.h.

◆ resize() [2/2]

template<class T>
void superdex::DynamicArray< T >::resize ( size_type newSize,
T const & value )
inline

Set the size.

If larger than the current size, new elements will be copy constructed from the given value.

Parameters
newSizeNew number of elements
valueValue to copy to new elements (if any).
Warning
The value parameter is not allowed to be a reference to an element within this same DynamicArray. In that case, consider using a copy of the value instead.
Remarks
The first time you call resize, capacity will be allocated for the exact size requested. However, subsequent calls to resize may allocate more than requested, similar to emplace_back.

Definition at line 437 of file dynamic_array.h.

◆ resize_noinit()

template<class T>
void superdex::DynamicArray< T >::resize_noinit ( size_type newSize)
inline

Set the size but do not initialize any new elements.

They will be in an undefined state!

Parameters
newSizeNew number of elements
Warning
This method may be used as an optimization, but only if you can guarantee that any new elements will be initialized before being used.
Note
Only supported for types satisfying kIsResizeNoInitSafe.
The first time you call resize_noinit, capacity will be allocated for the exact size requested. However, subsequent calls to resize_noinit may allocate more than requested, similar to emplace_back.

Definition at line 462 of file dynamic_array.h.

◆ shrink_to_fit()

template<class T>
void superdex::DynamicArray< T >::shrink_to_fit ( )
inline

Ensure that the capacity (memory allocated) is no larger than the size (memory used).

Definition at line 520 of file dynamic_array.h.

◆ size()

template<class T>
size_type superdex::DynamicArray< T >::size ( ) const
inlinenodiscard

Get the number of elements in the array.

Definition at line 383 of file dynamic_array.h.


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