#include "cetl/variable_length_array.hpp"
Public Types | |
| using | value_type = typename base::value_type |
| using | pointer = typename std::add_pointer_t<value_type> |
| using | iterator = typename std::add_pointer_t<value_type> |
| using | const_iterator = typename std::add_pointer_t<typename std::add_const_t<value_type>> |
| using | reverse_iterator = std::reverse_iterator<iterator> |
| using | const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using | difference_type = typename base::difference_type |
| using | size_type = typename base::size_type |
| using | allocator_type = typename base::allocator_type |
| using | reference = typename std::add_lvalue_reference_t<value_type> |
| using | const_reference = typename std::add_lvalue_reference_t<std::add_const_t<value_type>> |
Public Member Functions | |
| variable_length_array (const allocator_type &alloc) noexcept | |
| variable_length_array (size_type max_size_max, const allocator_type &alloc) noexcept | |
| variable_length_array (std::initializer_list< value_type > l, size_type max_size_max, const allocator_type &alloc) | |
| variable_length_array (std::initializer_list< value_type > l, const allocator_type &alloc) | |
| template<typename Count, typename = detail::enable_if_count_t<Count, size_type>> | |
| variable_length_array (Count count, const value_type &value, size_type max_size_max, const allocator_type &alloc) | |
| template<typename Count, typename = detail::enable_if_count_t<Count, size_type>> | |
| variable_length_array (Count count, const value_type &value, const allocator_type &alloc) | |
| template<class InputIt, typename = detail::enable_if_input_iterator_t<InputIt>> | |
| variable_length_array (InputIt first, InputIt last, size_type max_size_max, const allocator_type &alloc) | |
| template<class InputIt, typename = detail::enable_if_input_iterator_t<InputIt>> | |
| variable_length_array (InputIt first, InputIt last, const allocator_type &alloc) | |
| variable_length_array (const variable_length_array &rhs, const allocator_type &alloc) | |
| variable_length_array (const variable_length_array &rhs) | |
| variable_length_array & | operator= (const variable_length_array &rhs) |
| variable_length_array (variable_length_array &&rhs, const allocator_type &alloc) noexcept(std::allocator_traits< allocator_type >::is_always_equal::value) | |
| variable_length_array (variable_length_array &&rhs) noexcept | |
| variable_length_array & | operator= (variable_length_array &&rhs) noexcept(std::allocator_traits< allocator_type >::propagate_on_container_move_assignment::value||std::allocator_traits< allocator_type >::is_always_equal::value) |
| variable_length_array & | operator= (std::initializer_list< value_type > values) |
| constexpr bool | operator== (const variable_length_array &rhs) const noexcept |
| constexpr bool | operator!= (const variable_length_array &rhs) const noexcept |
| constexpr bool | operator< (const variable_length_array &rhs) const |
| constexpr bool | operator> (const variable_length_array &rhs) const |
| constexpr bool | operator<= (const variable_length_array &rhs) const |
| constexpr bool | operator>= (const variable_length_array &rhs) const |
| constexpr const_iterator | cbegin () const noexcept |
| constexpr const_iterator | cend () const noexcept |
| constexpr iterator | begin () noexcept |
| constexpr const_iterator | begin () const noexcept |
| constexpr iterator | end () noexcept |
| constexpr const_iterator | end () const noexcept |
| constexpr reverse_iterator | rbegin () noexcept |
| constexpr const_reverse_iterator | rbegin () const noexcept |
| constexpr const_reverse_iterator | crbegin () const noexcept |
| constexpr reverse_iterator | rend () noexcept |
| constexpr const_reverse_iterator | rend () const noexcept |
| constexpr const_reverse_iterator | crend () const noexcept |
| constexpr value_type * | data () noexcept |
| constexpr const value_type * | data () const noexcept |
| constexpr const value_type & | operator[] (size_type pos) const noexcept |
| constexpr value_type & | operator[] (size_type pos) noexcept |
| constexpr allocator_type | get_allocator () const noexcept |
| constexpr reference | at (size_type pos) |
| constexpr const_reference | at (size_type pos) const |
| constexpr reference | front () |
| constexpr const_reference | front () const |
| constexpr reference | back () |
| constexpr const_reference | back () const |
| constexpr bool | empty () const noexcept |
| void | shrink_to_fit () |
| constexpr size_type | capacity () const noexcept |
| constexpr size_type | size () const noexcept |
| void | reserve (const size_type desired_capacity) |
| constexpr size_type | max_size () const noexcept |
| constexpr void | clear () noexcept(std::is_nothrow_destructible< value_type >::value) |
| constexpr void | push_back (const value_type &value) |
| constexpr void | push_back (value_type &&value) |
| constexpr void | pop_back () noexcept(std::is_nothrow_destructible< value_type >::value) |
| iterator | erase (const_iterator pos) noexcept(std::is_nothrow_move_assignable< value_type >::value &&std::is_nothrow_destructible< value_type >::value) |
| iterator | erase (const_iterator first, const_iterator last) noexcept(std::is_nothrow_move_assignable< value_type >::value &&std::is_nothrow_destructible< value_type >::value) |
| iterator | insert (const_iterator pos, const value_type &value) |
| iterator | insert (const_iterator pos, value_type &&value) |
| iterator | insert (const_iterator pos, const size_type count, const value_type &value) |
| template<typename InputIt, typename = detail::enable_if_input_iterator_t<InputIt>> | |
| iterator | insert (const_iterator pos, InputIt first, InputIt last) |
| iterator | insert (const_iterator pos, std::initializer_list< value_type > values) |
| template<class... Args> | |
| void | emplace_back (Args &&... args) |
| constexpr void | resize (size_type count) |
| constexpr void | resize (size_type count, const value_type &value) |
| constexpr void | assign (size_type count, const value_type &value) |
| template<typename InputIt, typename = detail::enable_if_input_iterator_t<InputIt>> | |
| void | assign (InputIt first, InputIt last) |
| void | assign (std::initializer_list< value_type > values) |
Protected Types | |
| using | base = detail::variable_length_array_base<T, Allocator> |
Minimal, generic container for storing Cyphal variable-length arrays.
While this type shares similarities with std::vector it has several important properties that are different. First, the max_size_max maximum bound allows the array to enforce a maximum size whether or not the allocator properly implements the std::allocator_traits::max_size protocol (std::pmr::polymorphic_allocator, for example). This allows use of an allocator that is backed by statically allocated memory:
Even if cetl::variable_length_array::reserve() is not used the implementation will still use less memory then its STL counterpart:
Finally, when exceptions are disabled the cetl::variable_length_array will not exhibit undefined behaviour like std::vector does:
The allocator's optional reallocate extension is used only for trivially copyable storage. Non-trivial elements require replacement storage during capacity changes, even if the allocator could resize in place. Copy assignment also tries this extension when compatible destination storage must grow. On success it adopts the returned buffer, then copies the source values. On decline it releases the old buffer before allocating a replacement. An allocator that moves storage during reallocate may temporarily hold both buffers and copy bytes that assignment will overwrite; an allocator that grows in place can avoid that work. See Example 12: Growing a VLA with a buddy memory resource for a buddy resource demonstrating growth and copy assignment with trivial data. With a resource that supports only one outstanding allocation, reserve sufficient capacity before adding elements. If such a resource backs the source of an unequal-allocator move, the empty source still holds that allocation afterward (see the table below); call shrink_to_fit() on the source before allocating from the resource again.
After successful move construction or move assignment between distinct arrays, the source is empty. If its storage is transferred, its capacity becomes zero. If unequal allocators require element relocation, the source retains its original allocation and capacity for reuse. Call shrink_to_fit() on the empty source to release that storage explicitly; this requires no replacement allocation and is a no-op if capacity is already zero. Because the source keeps that storage, its allocator and any memory resource behind it must remain valid until the source is destroyed or shrunk, as for a moved-from std::vector. Retaining source capacity does not copy its spare capacity into the destination of an unequal-allocator move construction, which obtains only the storage required for the elements (rounded to bytes for packed bool). Every copy and move, whatever the allocators, also gives the destination the source's max_size_max bound.
In the table below, C is the source capacity before a successful move between distinct arrays. The source size becomes zero in every row. The same rules apply to packed variable_length_array<bool> and empty reserved sources. Self-move assignment leaves the array unchanged. Allocator propagation affects assignment only.
| Move operation | Allocator condition | Destination storage operations | Source capacity afterward |
|---|---|---|---|
Construction: VLA dst(std::move(src)) | Any | Adopt source storage; move-construct allocator | 0 |
Construction: VLA dst(std::move(src), alloc) | Equal, including is_always_equal | Adopt source storage | 0 |
Construction: VLA dst(std::move(src), alloc) | Unequal | Allocate storage and relocate elements | C (retained) |
Assignment: dst = std::move(src) | propagate_on_container_move_assignment is true | Release old storage; adopt source allocator and storage | 0 |
Assignment: dst = std::move(src) | No propagation; equal, including is_always_equal | Release old storage; adopt source storage | 0 |
Assignment: dst = std::move(src) | No propagation; unequal; destination capacity sufficient | Move elements into existing storage | C (retained) |
Assignment: dst = std::move(src) | No propagation; unequal; destination capacity insufficient | Release old storage; allocate replacement storage and relocate elements | C (retained) |
With exceptions enabled, failed construction destroys every successfully constructed destination element and releases abandoned storage. Failed reserve() or shrink_to_fit() preserves the original values when relocation copies elements. If a throwing move-only element is relocated, source values may already have been moved from; the container retains ownership and valid size/capacity bookkeeping, but those values are not restored.
Failed construction during resize() destroys the new suffix and retains the original size. Capacity acquired before the failure may remain. Assignment provides valid lifetime and ownership bookkeeping after failure; previously assigned values need not be restored, and replacement of the old buffer may leave an empty array. Move assignment with non-propagating, unequal allocators releases an insufficient destination buffer before allocating its replacement, avoiding simultaneous ownership of the old and new destination buffers. If replacement allocation or element construction throws, the destination is valid but empty. If the existing capacity suffices, a throwing element assignment may leave destination values partially updated. Throwing element moves may also modify source values; the successful-move postconditions above do not apply to failed operations. Element destruction and allocator deallocation must not throw. With exceptions disabled, no rollback is provided, except that an unequal-allocator move construction or move assignment that cannot obtain destination storage leaves the destination empty and the source unchanged. Such a failure is detected by the source remaining non-empty.
| T | The type of elements in the array. |
| Allocator | The allocator type to use for all allocations. |
| using cetl::variable_length_array< T, Allocator >::allocator_type = typename base::allocator_type |
Per the std::uses_allocator protocol.
| using cetl::variable_length_array< T, Allocator >::const_iterator = typename std::add_pointer_t<typename std::add_const_t<value_type>> |
STL-like declaration of the const iterator type.
| using cetl::variable_length_array< T, Allocator >::const_reference = typename std::add_lvalue_reference_t<std::add_const_t<value_type>> |
STL-like declaration of constant-reference type.
| using cetl::variable_length_array< T, Allocator >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
STL-like declaration of the const reverse iterator type.
| using cetl::variable_length_array< T, Allocator >::difference_type = typename base::difference_type |
STL-like declaration of the container's difference type.
| using cetl::variable_length_array< T, Allocator >::iterator = typename std::add_pointer_t<value_type> |
STL-like declaration of the iterator type.
| using cetl::variable_length_array< T, Allocator >::pointer = typename std::add_pointer_t<value_type> |
STL-like declaration of pointer type.
| using cetl::variable_length_array< T, Allocator >::reference = typename std::add_lvalue_reference_t<value_type> |
STL-like declaration of reference type.
| using cetl::variable_length_array< T, Allocator >::reverse_iterator = std::reverse_iterator<iterator> |
STL-like declaration of the reverse iterator type.
| using cetl::variable_length_array< T, Allocator >::size_type = typename base::size_type |
STL-like declaration of the container's size type.
| using cetl::variable_length_array< T, Allocator >::value_type = typename base::value_type |
STL-like declaration of the container's storage type.
|
inlineexplicitnoexcept |
Required constructor for std::uses_allocator protocol.
| alloc | Allocator to use for all allocations. |
References std::numeric_limits::max().
Referenced by operator<(), operator<=(), operator=(), operator>(), operator>=(), variable_length_array(), variable_length_array(), and variable_length_array().

|
inlineexplicitnoexcept |
Required constructor for std::uses_allocator protocol.
| max_size_max | Clamping value for the maximum size of this array. That is, cetl::variable_length_array::max_size() will return std::min(max_size_max, std::allocator_traits<allocator_type>::max_size(alloc)) |
| alloc | Allocator to use for all allocations. |
|
inline |
Initializer syntax constructor with maximum max size.
| l | Initializer list of elements to copy into the array. |
| max_size_max | Clamping value for the maximum size of this array. That is, cetl::variable_length_array::max_size() will return std::min(max_size_max, std::allocator_traits<allocator_type>::max_size(alloc)) |
| alloc | Allocator to use for all allocations. |
References std::initializer_list::begin(), reserve(), and std::initializer_list::size().
|
inline |
Initializer syntax constructor.
| l | Initializer list of elements to copy into the array. |
| alloc | Allocator to use for all allocations. |
References variable_length_array().
|
inline |
Count-value constructor with maximum max size.
Constructs count copies of value, as std::vector(count, value, alloc) does, allocating storage for exactly count elements. The count may be any type that converts to size_type, but not a braced list: variable_length_array({x}, n, alloc) selects the initializer-list constructor. There is no (count, alloc) overload, because variable_length_array(n, alloc) sets max_size_max. With exceptions disabled, the array is truncated to max_size() or to the storage the allocator provides, which the caller can detect by comparing size() with count.
| Count | The type of count. |
| count | The number of elements to construct. |
| value | The value to copy into each element. |
| max_size_max | Clamping value for the maximum size of this array. That is, cetl::variable_length_array::max_size() will return std::min(max_size_max, std::allocator_traits<allocator_type>::max_size(alloc)) |
| alloc | Allocator to use for all allocations. |
| std::length_error | if count is greater than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to hold count elements. |
References max_size().
|
inline |
Count-value constructor.
Constructs count copies of value, as std::vector(count, value, alloc) does. Has the same guarantees as the constructor that also takes max_size_max.
| Count | The type of count. |
| count | The number of elements to construct. |
| value | The value to copy into each element. |
| alloc | Allocator to use for all allocations. |
| std::length_error | if count is greater than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to hold count elements. |
References variable_length_array().
|
inline |
Range constructor with maximum max size.
| InputIt | The type of the range's iterators. |
| first | The beginning of the range. |
| last | The end of the range. |
| max_size_max | Clamping value for the maximum size of this array. That is, cetl::variable_length_array::max_size() will return std::min(max_size_max, / std::allocator_traits<allocator_type>::max_size(alloc)) |
| alloc | Allocator to use for all allocations. |
|
inline |
Range constructor.
| InputIt | The type of the range's iterators. |
| first | The beginning of the range. |
| last | The end of the range. |
| alloc | Allocator to use for all allocations. |
References variable_length_array().
|
inline |
Replace the contents with the elements in [first, last), reusing existing storage where possible.
Single-pass input iterators are traversed once; forward ranges are measured before assignment. Move iterators move from the source elements. Forward ranges require no relocation of existing elements. The source range must not refer to elements of this array.
Forward ranges are checked against max_size() before anything changes. They release insufficient storage and then allocate storage for the whole range at once; if that allocation fails the array is left empty. Single-pass ranges grow one element at a time and detect an excessive length only on reaching max_size(), after the first max_size() elements have been assigned. If any element operation, iterator operation, allocation, or single-pass length check fails, the array remains valid but may be partially updated.
With exceptions disabled, forward ranges are truncated to max_size() or left empty by failed allocation, which the caller can detect by comparing size() with std::distance(first, last). Single-pass ranges stop at max_size() or at failed growth and keep the assigned prefix; the element that could not be stored is consumed. That cannot be distinguished from a source that ended at the same length, so bound single-pass sources by the remaining max_size() and reserve() capacity beforehand when truncation must be detected.
| std::length_error | if the source range exceeds max_size(). |
| std::bad_alloc | if storage cannot be obtained: for the whole forward range, or for the next element of a single-pass range. |
|
inlineconstexpr |
Set count elements to the given value.
Grow the array if needed else set the size to count without reducing capacity. Like assign(first, last), insufficient storage is released before replacement storage is allocated, so growth needs no relocation; allocation failure or a throwing copy then leaves the array empty or partial.
| count | Number of elements, starting from 0, to set. |
| value | The value to set. It must not refer to an element of this array. |
| std::length_error | if the size requested is greater than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to size up to count. |
References max_size(), std::min(), and resize().
Referenced by assign(), and operator=().

|
inline |
Replace the contents with the initializer list. Has the same guarantees as assign(first, last).
References assign(), std::initializer_list::begin(), and std::initializer_list::end().
|
inlineconstexpr |
Returns a reference to the element at specified location pos, with bounds checking.
| pos | Position of the element to return. |
References operator[](), and size().
|
inlineconstexpr |
Returns a const reference to the element at specified location pos, with bounds checking.
| pos | Position of the element to return. |
References operator[](), and size().
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexprnoexcept |
Provides direct, unsafe access to the internal data buffer.
This pointer is invalidated by calls to shrink_to_fit and reserve.
Referenced by rend().

|
inlineconstexprnoexcept |
The number of elements that can be stored in the array without further allocations.
This number will only grow through calls to reserve and can shrink through calls to shrink_to_fit. This value shall never exceed max_size.
|
inlineconstexprnoexcept |
Provides direct, unsafe access to the internal data buffer.
This pointer is invalidated by calls to shrink_to_fit and reserve.
Referenced by erase(), erase(), and operator<().

|
inlineconstexprnoexcept |
Pointer to memory location after the last, valid element.
This pointer is invalidated by calls to shrink_to_fit and reserve.
Referenced by erase(), erase(), and operator<().

|
inlineconstexprnoexcept |
Destroys all elements in the list but does not release any capacity.
|
inlineconstexprnoexcept |
Provides direct, unsafe access to the internal data buffer.
This pointer is invalidated by calls to shrink_to_fit and reserve.
|
inlineconstexprnoexcept |
Provides direct, unsafe access to the internal data buffer.
This pointer is invalidated by calls to shrink_to_fit and reserve.
|
inline |
Like push_back but constructs the object directly in uninitialized memory.
As with std::vector, the arguments may refer to elements of this array, even when the call grows the storage.
| throw | std::length_error if there was not enough storage for an additional element. If exceptions are disabled then the caller must check the array size before and after calling the method to determine if it succeeded. |
References std::allocator_traits::construct(), std::forward(), and max_size().
Referenced by push_back(), and push_back().

|
inlineconstexprnoexcept |
Query if the container has any elements in it at all.
true if the container is empty, false otherwise.
|
inlineconstexprnoexcept |
|
inlinenoexcept |
Removes the elements in [first, last), as std::vector::erase does.
Later elements are move-assigned toward the front and the vacated elements at the end are destroyed. Capacity and max_size() are unchanged, and iterators before first remain valid. An empty range has no effect.
| first | The first element to remove. |
| last | One past the last element to remove. [first, last) must be a valid range of this array. |
| * | Any exception thrown by value_type's move assignment. The array then keeps its size and every element is valid, but elements from first onward may have been assigned or moved from. |
References cbegin(), cend(), CETL_DEBUG_ASSERT, and end().
|
inlinenoexcept |
Removes the element at pos, as std::vector::erase does.
Has the same guarantees as erase(first, last).
| pos | The element to remove. It must be dereferenceable, so it cannot be end(). |
References cbegin(), cend(), CETL_DEBUG_ASSERT, and erase().
Referenced by erase().

|
inlineconstexpr |
Returns a reference to the first element in the array.
Calling this method on an empty array is undefined.
References CETL_DEBUG_ASSERT, and size().
Referenced by back(), and back().

|
inlineconstexpr |
Returns a const reference to the first element in the array.
Calling this method on an empty array is undefined.
References CETL_DEBUG_ASSERT, and size().
|
inlineconstexprnoexcept |
STL-like access to a copy of the internal allocator.
|
inline |
Inserts count copies of value before pos, as std::vector::insert does.
value may be an element of this array. Iterators at or after pos are invalidated, and all iterators are if capacity grows; capacity grows geometrically, as for push_back(), so repeated insertion takes amortized constant time per element moved.
The new elements are constructed at the end and rotated into place, so value_type must be move-assignable and swappable, as std::vector requires. If constructing a new element throws, the elements constructed so far are destroyed and the array is unchanged, although capacity acquired for the insertion may remain. If moving the existing elements throws, every element remains valid but their order is unspecified.
With exceptions disabled, an insertion that would exceed max_size(), or for which the allocator does not provide storage, has no effect; detect it by comparing size() before and after.
| pos | The element before which to insert; may be end(). |
| count | The number of copies to insert. |
| value | The value to copy. |
pos if nothing was inserted. | std::length_error | if size() + count would exceed max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory. |
|
inline |
Inserts a copy of value before pos, as std::vector::insert does.
Has the same guarantees as insert(pos, count, value); value may be an element of this array.
References insert().
Referenced by insert(), and insert().

|
inline |
Inserts the elements of [first, last) before pos, in order, as std::vector::insert does.
The range must not refer to elements of this array. Forward ranges are measured first and have the same guarantees as insert(pos, count, value). Single-pass ranges are appended one element at a time and then rotated into place; if that fails with exceptions enabled, the appended elements are destroyed and the array is otherwise unchanged. With exceptions disabled, a single-pass range stops at max_size() or at failed growth and keeps the inserted prefix, as assign(first, last) does.
pos if the range is empty. | std::length_error | if the inserted elements would exceed max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory. |
|
inline |
Inserts the elements of values before pos.
Has the same guarantees as insert(pos, first, last).
pos if values is empty. References std::initializer_list::begin(), std::initializer_list::end(), and insert().
|
inline |
Inserts value before pos by moving it, as std::vector::insert does.
Has the same guarantees as insert(pos, count, value). As for any rvalue argument, value must not refer to an element of this array.
|
inlineconstexprnoexcept |
Returns the, theoretical, maximum number of elements that can be stored in this container.
It does not take into account the current state of the allocator. That is, if the allocator is out of memory this method will still return the maximum number of elements that could be stored if the allocator had enough memory, however, it will always return the maximum size passed into the constructor if that value is less than the allocator's max_size.
References std::numeric_limits::max(), std::allocator_traits::max_size(), and std::min().
Referenced by assign(), emplace_back(), reserve(), resize(), resize(), and variable_length_array().

|
inlineconstexpr |
Compares the elements lexicographically, as std::vector's operator< does before C++20: the first unequal pair decides, and otherwise the shorter array is less.
Requires value_type to be comparable with operator<. In C++20 these four operators are replaced by operator<=>, as they are for std::vector.
References cbegin(), cend(), std::lexicographical_compare(), and variable_length_array().
|
inlineconstexpr |
Lexicographic comparison; see operator<.
References variable_length_array().
|
inline |
Replace the contents with the initializer list, keeping the allocator and max_size().
Equivalent to assign(values), with the same guarantees.
| values | The elements to copy into the array. |
*this | std::length_error | if values has more elements than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to hold values. |
References assign(), and variable_length_array().
|
inlineconstexpr |
Lexicographic comparison; see operator<.
References variable_length_array().
|
inlineconstexpr |
Lexicographic comparison; see operator<.
References variable_length_array().
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Direct access to an element.
If pos is > size the behavior is undefined.
The returned reference is valid while this object is unless reserve or shrink_to_fit is called.
| pos | The index of the element to access. |
pos.
|
inlineconstexprnoexcept |
Remove and destroy the last item in the array.
This reduces the array size by 1 unless the array is already empty.
References std::addressof(), and std::allocator_traits::destroy().
|
inlineconstexpr |
Allocate a new element on to the back of the array and copy value into it.
Grows size by 1 and may grow capacity.
If exceptions are disabled the caller must check before and after to see if the size grew to determine success. If using exceptions this method throws std::length_error if the size of this collection is at capacity or std::bad_alloc if the allocator failed to provide enough memory.
If exceptions are disabled use the following logic:
const size_t size_before = my_array.size();
my_array.push_back(element);
if (size_before == my_array.size())
{
// failure
if (size_before == my_array.max_size())
{
// length_error: you probably should have checked this first.
}
else
{
// bad_alloc: out of memory
}
} // else, success.
References emplace_back().
|
inlineconstexpr |
Allocate a new element on to the back of the array and move value into it.
Grows size by 1 and may grow capacity.
See variable_length_array::push_back(value_type&) for full documentation.
| std::length_error | if the size of this collection is at capacity. |
| std::bad_alloc | if memory was needed and none could be allocated. |
References emplace_back().
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
A reverse iterator to the position before the first element.
References begin().
|
inline |
Ensure enough memory is allocated to store at least the desired_capacity number of elements.
| desired_capacity | The number of elements to allocate, but not initialize, memory for. |
References max_size().
Referenced by variable_length_array().

|
inlineconstexpr |
Resizes internal storage to count elements default initializing any added elements over the current size() and deleting any elements under the current size().
If size() == count then this method has no effect.
| count | The new size to set for this container. |
| * | If exceptions are enabled then any exceptions that value_type constructors or destructors throw will escape this call |
| std::length_error | if the size requested is greater than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to size up to count. |
References max_size().
Referenced by assign().

|
inlineconstexpr |
Resizes internal storage to count elements copy-initializing any added elements over the current size() and deleting any elements under the current size().
If size() == count then this method has no effect.
| count | The new size to set for this container. |
| value | The value to copy into any new elements created by the operation. |
| * | If exceptions are enabled then any exceptions that value_type constructors or destructors throw will escape this call |
| std::length_error | if the size requested is greater than max_size(). |
| std::bad_alloc | if the container cannot obtain enough memory to size up to count. |
References max_size().
|
inline |
Reduce the amount of memory held by this object to the minimum required based on size.
This method may not actually deallocate any memory if there is not enough memory to allocate a smaller buffer before moving the existing elements and freeing the larger buffer. Allocation failure triggers a CETL_DEBUG_ASSERT when CETL_ENABLE_DEBUG_ASSERT is enabled; otherwise, the original buffer and capacity are retained and std::bad_alloc is suppressed.
| if | any items throw while being moved. |
References CETL_DEBUG_ASSERT.
|
inlineconstexprnoexcept |
The current number of elements in the array.
This number increases with each successful call to push_back and decreases with each call to pop_back (when size is > 0).
Referenced by at(), at(), back(), back(), front(), front(), and cetl::variable_length_array< bool, Allocator >::set().
