|
SuperDex Physics C++ API
|
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. | |
| Allocator * | get_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. | |
| DynamicArray & | operator= (DynamicArray &&other) |
| Move Assignment: Replace the contents of this DynamicArray by moving memory or values from another one. | |
| DynamicArray & | operator= (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> | |
| DynamicArray & | operator= (InputContainerT const &other) |
| Copy Assignment: Replace the contents of this DynamicArray by copying values from another iterable container of compatible type. | |
| DynamicArray & | operator= (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. | |
A dynamically resizable array with syntax and behavior similar to std::pmr::vector.
| T | Element value type. |
Definition at line 105 of file dynamic_array.h.
| using superdex::DynamicArray< T >::const_iterator = T const* |
Definition at line 111 of file dynamic_array.h.
| using superdex::DynamicArray< T >::iterator = T* |
Definition at line 112 of file dynamic_array.h.
| using superdex::DynamicArray< T >::size_type = size_t |
Definition at line 114 of file dynamic_array.h.
| using superdex::DynamicArray< T >::value_type = T |
Definition at line 113 of file dynamic_array.h.
|
default |
Construct an empty DynamicArray with the default allocator.
|
inlineexplicit |
Construct an empty DynamicArray with a specific allocator.
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 126 of file dynamic_array.h.
|
inlineexplicit |
Construct a DynamicArray with an initial size.
All elements will be default constructed or zero-initialized (for POD types).
| size | Initial size (number of elements, not bytes) |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 135 of file dynamic_array.h.
|
inline |
Construct a DynamicArray filled with copies of the specified value.
| FromT | Input value type. Must be same or convertible to type T. |
| size | Initial size (number of elements, not bytes) |
| defaultValue | Value to copy to all new array elements. |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 152 of file dynamic_array.h.
|
inline |
Construct a DynamicArray and copy values from the half-open range: [rangeBegin, rangeEnd).
| InputIt | Input forward iterator type (typically deduced). |
| rangeBegin | Iterator pointing to the first input value to copy. |
| rangeEnd | Iterator pointing ONE PAST the last input value to copy. |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 177 of file dynamic_array.h.
|
inline |
Construct a DynamicArray and copy values from a std::initializer_list.
| list | List from which values will be copied. |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 192 of file dynamic_array.h.
|
inlineexplicit |
Construct a DynamicArray and copy values from another iterable container type like superdex::Span, std::vector, std::list, etc...
| InputContainerT | Input container type. Must support std::begin and std::end. |
| other | Container from which values will be copied. |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 209 of file dynamic_array.h.
|
inline |
Construct a DynamicArray and copy values from another one.
| other | Another DynamicArray from which values will be copied. |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 218 of file dynamic_array.h.
|
inline |
Copy construct from another DynamicArray.
Use the same allocator.
| other | Another DynamicArray from which the allocator and the values will be copied. |
Definition at line 226 of file dynamic_array.h.
|
inline |
Construct a DynamicArray by moving memory or values from another one.
| other | Another DynamicArray from which memory or values will be moved |
| allocator | Pointer to a polymorphic allocator. Must outlive this DynamicArray object. |
Definition at line 240 of file dynamic_array.h.
|
inlinenoexcept |
Move construct from another DynamicArray.
Use the same allocator.
| other | Another DynamicArray from which memory will be moved. Will be empty after this call. |
Definition at line 269 of file dynamic_array.h.
|
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.
|
inline |
Add values to the end of this DynamicArray by copying them from another iterable container.
| InputContainerT | Another iterable container type. Must support std::begin and std::end. |
| container | Container from which value will be copied. |
Definition at line 823 of file dynamic_array.h.
|
inline |
Add values to the end of this DynamicArray by copying them from the half-open range [rangeBegin, rangeEnd).
| InputIt | Input iterator type (typically deduced). |
| rangeBegin | Iterator pointing to the first input value to copy. |
| rangeEnd | Iterator pointing ONE PAST the last input value to copy. |
Definition at line 795 of file dynamic_array.h.
|
inline |
Replace the contents of this DynamicArray by copying values from the half-open range [rangeBegin, rangeEnd).
| InputIt | Input iterator type (typically deduced). |
| rangeBegin | Iterator pointing to the first value to copy from. |
| rangeEnd | Iterator pointing ONE PAST the last value to copy from. |
Definition at line 720 of file dynamic_array.h.
|
inlinenodiscard |
Get a reference to the last element.
Array must not be empty.
Definition at line 353 of file dynamic_array.h.
|
inlinenodiscard |
Get a const reference to the last element.
Array must not be empty.
Definition at line 361 of file dynamic_array.h.
|
inlinenodiscard |
Get an iterator pointing to the beginning of the array.
Definition at line 295 of file dynamic_array.h.
|
inlinenodiscard |
Get a const iterator pointing to the beginning of the array.
Definition at line 302 of file dynamic_array.h.
|
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.
|
inlinenodiscard |
Get a const iterator pointing to the beginning of the array.
Definition at line 309 of file dynamic_array.h.
|
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.
|
inline |
Set the size to zero.
Does not deallocate memory.
Definition at line 512 of file dynamic_array.h.
|
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.
|
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.
|
inline |
Emplace a new element at the end of the array.
Unlike std::vector, we skip past the first few reallocations by reserving a capacity of kGrowthPatternStartSize the first time. See GetNextCapacity() for details.
| Args | Any types that can be passed to type T's constructor. |
| args | Any arguments that can be passed to type T's constructor. |
Definition at line 554 of file dynamic_array.h.
|
inlinenodiscard |
Return true if the array is empty (zero size).
Definition at line 397 of file dynamic_array.h.
|
inlinenodiscard |
Get an iterator pointing to the next element AFTER the end of the array.
Definition at line 316 of file dynamic_array.h.
|
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.
|
inline |
Remove one element from this array.
Any later elements will be shifted down to preserve order.
| it_ | Iterator pointing to the element to remove. |
Definition at line 676 of file dynamic_array.h.
|
inline |
Remove the half-open range [rangeBegin, rangeEnd) from this array.
Any later elements will be shifted down to preserve order.
| 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.
|
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.
| it | Iterator pointing to the element to remove. |
Definition at line 695 of file dynamic_array.h.
|
inlinenodiscard |
Get a reference to the first element.
Array must not be empty.
Definition at line 337 of file dynamic_array.h.
|
inlinenodiscard |
Get a const reference to the first element.
Array must not be empty.
Definition at line 345 of file dynamic_array.h.
|
inlinenodiscard |
Get a pointer to the polymorphic allocator.
Definition at line 830 of file dynamic_array.h.
|
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.
|
inline |
Move Assignment: Replace the contents of this DynamicArray by moving memory or values from another one.
| other | Another DynamicArray from which memory or values will be moved. |
Definition at line 877 of file dynamic_array.h.
|
inline |
Copy Assignment: Replace the contents of this DynamicArray by copying values from another one.
| other | Another DynamicArray from which values will be copied. |
Definition at line 857 of file dynamic_array.h.
|
inline |
Copy Assignment: Replace the contents of this DynamicArray by copying values from another iterable container of compatible type.
| InputContainerT | Another container type. Must support std::begin and std::end. |
| other | Container from which values will be copied. |
Definition at line 939 of file dynamic_array.h.
|
inline |
Copy Assignment: Replace the contents of this DynamicArray by copying values from a std::initializer_list.
| list | List of values to copy |
Definition at line 920 of file dynamic_array.h.
|
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.
|
inlinenodiscard |
Get a reference to the value at index i.
Definition at line 837 of file dynamic_array.h.
|
inlinenodiscard |
Get a reference to the value at index i.
Definition at line 845 of file dynamic_array.h.
|
inline |
Remove the last element of the array (must not be empty).
Definition at line 623 of file dynamic_array.h.
|
inline |
Default construct a new element at the end of the array.
Definition at line 615 of file dynamic_array.h.
|
inline |
Move the value to a new element at the end of the array.
| value | Value to be moved |
Definition at line 600 of file dynamic_array.h.
|
inline |
Copy the value to a new element at the end of the array.
| value | Value to be copied |
Definition at line 585 of file dynamic_array.h.
|
inline |
Ensure that this array has at least the specified capacity.
| newCapacity | Desired capacity measured by number of elements (not bytes). |
Definition at line 502 of file dynamic_array.h.
|
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.
| Args | Any argument types supported by one of the DynamicArray constructors. |
| args | Any parameter types supported by one of the DynamicArray constructors. |
Definition at line 489 of file dynamic_array.h.
|
inline |
Set the size.
If larger than the current size, new elements will be default constructed (zero-initialized for POD types).
| newSize | New number of elements |
Definition at line 411 of file dynamic_array.h.
|
inline |
Set the size.
If larger than the current size, new elements will be copy constructed from the given value.
| newSize | New number of elements |
| value | Value to copy to new elements (if any). |
Definition at line 437 of file dynamic_array.h.
|
inline |
Set the size but do not initialize any new elements.
They will be in an undefined state!
| newSize | New number of elements |
Definition at line 462 of file dynamic_array.h.
|
inline |
Ensure that the capacity (memory allocated) is no larger than the size (memory used).
Definition at line 520 of file dynamic_array.h.
|
inlinenodiscard |
Get the number of elements in the array.
Definition at line 383 of file dynamic_array.h.