Pigweed
C/C++ API Reference
|
Public Types | |
using | value_type = T |
using | size_type = SizeType |
using | reference = value_type & |
using | const_reference = const value_type & |
using | pointer = value_type * |
using | const_pointer = const value_type * |
using | iterator = containers::PtrIterator< DynamicVector > |
using | const_iterator = containers::ConstPtrIterator< DynamicVector > |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
using | allocator_type = Allocator |
Public Member Functions | |
constexpr | DynamicVector (Allocator &allocator) |
DynamicVector (const DynamicVector &)=delete | |
DynamicVector & | operator= (const DynamicVector &)=delete |
constexpr | DynamicVector (DynamicVector &&)=default |
constexpr DynamicVector & | operator= (DynamicVector &&)=default |
iterator | begin () |
const_iterator | begin () const |
const_iterator | cbegin () const |
iterator | end () |
const_iterator | end () const |
const_iterator | cend () const |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | crbegin () const |
reverse_iterator | rend () |
const_reverse_iterator | rend () const |
const_reverse_iterator | crend () const |
constexpr allocator_type & | get_allocator () const |
Returns the vector's allocator. | |
bool | empty () const |
Checks if the vector is empty. | |
size_type | size () const |
Returns the number of elements in the vector. | |
size_type | capacity () const |
size_type | max_size () const |
Maximum possible value of size() , ignoring allocator limitations. | |
void | reserve (size_type new_capacity) |
void | reserve_exact (size_type new_capacity) |
bool | try_reserve (size_type new_capacity) |
bool | try_reserve_exact (size_type new_capacity) |
void | shrink_to_fit () |
Reduces memory usage by releasing unused capacity. | |
reference | operator[] (size_type pos) |
const_reference | operator[] (size_type pos) const |
reference | at (size_type pos) |
const_reference | at (size_type pos) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
pointer | data () |
const_pointer | data () const |
void | assign (size_type count, const value_type &value) |
bool | try_assign (size_type count, const value_type &value) |
void | assign (std::initializer_list< T > init) |
bool | try_assign (std::initializer_list< T > init) |
void | push_back (const value_type &value) |
void | push_back (value_type &&value) |
bool | try_push_back (const value_type &value) |
bool | try_push_back (value_type &&value) |
void | pop_back () |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
template<typename... Args> | |
bool | try_emplace_back (Args &&... args) |
iterator | erase (const_iterator pos) |
iterator | erase (const_iterator first, const_iterator last) |
void | resize (size_type count) |
void | resize (size_type count, const value_type &value) |
bool | try_resize (size_type count) |
bool | try_resize (size_type count, const value_type &value) |
void | clear () |
Removes all elements from the vector. | |
void | swap (DynamicVector &other) |
Array-backed list similar to std::vector
, but optimized for embedded.
Key features of pw::DynamicVector
.
pw::Allocator
for memory operations.std::vector
API, but adds try_*
versions of operations that crash on allocation failure.assign()
& try_assign()
.push_back()
& try_push_back()
emplace_back()
& try_emplace_back()
resize()
& try_resize()
.reserve()
/try_reserve()
and shrink_to_fit()
to manage memory usage.constexpr
constructible.size_type
of uint16_t
.pw::Allocator::Resize()
when possible to maximize efficiency.pw::DynamicVector
is currently implemented as a wrapper around pw::DynamicDeque
. Some operations are more expensive than they need to be, and DynamicVector
objects are larger than necessary. This overhead will be eliminated in the future (see b/424613355).
|
inlineexplicitconstexpr |
Constructs an empty DynamicVector
using the provided allocator.
allocator | The allocator to use for memory management. |
|
inline |
Assigns new contents to the vector, replacing its current contents.
count | The number of elements to assign. |
value | The value to copy. |
true
if successful, false
otherwise.
|
inline |
Assigns new contents to the vector from an initializer list.
init | The initializer list to copy elements from. |
true
if successful, false
otherwise.
|
inline |
Returns a reference to the element at specified location pos
, with bounds checking.
Crashes if pos
is not within the range [0, size())
.
pos | The index of the element to access. |
|
inline |
Returns a const reference to the element at specified location pos
, with bounds checking.
Crashes if pos
is not within the range [0, size())
.
pos | The index of the element to access. |
|
inline |
Returns a reference to the last element in the vector.
Calling back()
on an empty vector is undefined behavior.
|
inline |
Returns a const reference to the last element in the vector.
Calling back()
on an empty vector is undefined behavior.
|
inline |
Returns the total number of elements that the vector can hold without requiring reallocation.
|
inline |
|
inline |
Returns a const pointer to the underlying array serving as element storage.
nullptr
if the vector is empty.
|
inline |
Constructs an element in place at the back of the vector.
Note: This operation is potentially fallible if memory allocation is required and fails. Use try_emplace_back()
for a fallible version.
|
inline |
Erases the specified range of elements from the vector.
first | The first element to erase. |
last | The last element to erase. |
|
inline |
Erases the specified element from the vector.
pos | Iterator to the element to remove. |
|
inline |
Returns a reference to the first element in the vector.
Calling front()
on an empty vector is undefined behavior.
|
inline |
Returns a const reference to the first element in the vector.
Calling front()
on an empty vector is undefined behavior.
|
inline |
Returns a reference to the element at specified location pos
.
No bounds checking is performed.
pos | The index of the element to access. |
|
inline |
Returns a const reference to the element at specified location pos
.
No bounds checking is performed.
pos | The index of the element to access. |
|
inline |
Removes the last element from the vector.
Calling pop_back()
on an empty vector is undefined behavior.
|
inline |
Adds an element to the back of the vector.
Note: This operation is potentially fallible if memory allocation is required and fails. Use try_push_back()
for a fallible version.
|
inline |
Adds an element to the back of the vector (move version).
Note: This operation is potentially fallible if memory allocation is required and fails.
|
inline |
Requests that the vector capacity be at least new_capacity
elements.
Crashes if allocation fails.
new_capacity | The minimum desired capacity. |
|
inline |
Requests that the vector capacity be exactly new_capacity
elements.
Crashes if allocation fails.
new_capacity | The minimum desired capacity. |
|
inline |
Resizes the vector to contain count
elements.
If count
is smaller than the current size, the content is reduced to the first count
elements. If count
is greater than the current size, new elements are appended and default-constructed.
count | New size of the vector. |
|
inline |
Resizes the vector to contain count
elements, value-initializing new elements.
If count
is smaller than the current size, the content is reduced to the first count
elements. If count
is greater than the current size, new elements are appended and copy-constructed from value
.
count | New size of the vector. |
value | Value to initialize new elements with. |
|
inline |
Swaps the contents with another DynamicVector.
other | The other vector to swap with. |
|
inline |
Attempts to construct an element in place at the back of the vector.
Returns true
on success, or false
if allocation fails.
args | Arguments to forward to the element's constructor. |
true
if successful, false
otherwise.
|
inline |
Attempts to add an element to the back of the vector.
Returns true
on success, or false
if allocation fails.
value | The value to add. |
true
if successful, false
otherwise.
|
inline |
Attempts to add an element to the back of the vector (move version).
Returns true
on success, or false
if allocation fails.
value | The value to add. |
true
if successful, false
otherwise.
|
inline |
Attempts to request that the vector capacity be at least new_capacity
elements.
Returns true
on success, or false
if allocation fails.
new_capacity | The minimum desired capacity. |
true
if successful, false
otherwise.
|
inline |
Attempts to set the vector capacity to exactly new_capacity
elements.
Returns true
on success, or false
if allocation fails.
new_capacity | The exact desired capacity. |
true
if successful, false
otherwise.
|
inline |
Attempts to resize the vector to contain count
elements.
count | New size of the vector. |
true
if successful, false
otherwise.
|
inline |
Attempts to resize the vector to contain count
elements, value-initializing new elements.
count | New size of the vector. |
value | Value to initialize new elements with. |
true
if successful, false
otherwise.