Pigweed
C/C++ API Reference
|
Public Types | |
using | allocator_type = Allocator |
using | const_iterator = containers::internal::DequeIterator< const Derived > |
using | const_pointer = const value_type * |
using | const_reference = const value_type & |
using | difference_type = ptrdiff_t |
using | iterator = containers::internal::DequeIterator< Derived > |
using | pointer = value_type * |
using | reference = value_type & |
using | size_type = typename CountAndCapacityType::size_type |
using | value_type = ValueType |
![]() | |
using | value_type = ValueType |
using | size_type = typename CountAndCapacityType::size_type |
using | difference_type = ptrdiff_t |
using | reference = value_type & |
using | const_reference = const value_type & |
using | pointer = value_type * |
using | const_pointer = const value_type * |
using | iterator = containers::internal::DequeIterator< Derived > |
using | const_iterator = containers::internal::DequeIterator< const Derived > |
![]() | |
using | size_type = typename CountAndCapacityType::size_type |
Public Member Functions | |
constexpr | DynamicDeque (Allocator &allocator) noexcept |
DynamicDeque (const DynamicDeque &)=delete | |
DynamicDeque & | operator= (const DynamicDeque &)=delete |
constexpr | DynamicDeque (DynamicDeque &&other) noexcept |
DynamicDeque & | operator= (DynamicDeque &&other) noexcept |
template<typename InputIt , typename = containers::internal::EnableIfInputIterator<InputIt>> | |
iterator | insert (const_iterator pos, InputIt first, InputIt last) |
iterator | insert (const_iterator pos, const value_type &value) |
iterator | insert (const_iterator pos, value_type &&value) |
iterator | insert (const_iterator pos, size_type count, const value_type &value) |
iterator | insert (const_iterator pos, std::initializer_list< value_type > ilist) |
bool | try_reserve (size_type new_capacity) |
void | reserve (size_type new_capacity) |
Increases capacity() to at least new_capacity . Crashes on failure. | |
bool | try_reserve_exact (size_type new_capacity) |
void | reserve_exact (size_type new_capacity) |
Increases capacity() to exactly new_capacity . Crashes on failure. | |
void | shrink_to_fit () |
Attempts to reduce capacity() to size() . Not guaranteed to succeed. | |
constexpr size_type | max_size () const noexcept |
constexpr allocator_type & | get_allocator () const |
Returns the deque's allocator. | |
void | swap (DynamicDeque &other) noexcept |
Swaps the contents of two deques. No allocations occur. | |
bool | try_assign (size_type count, const value_type &value) |
template<typename It , int & ..., typename = containers::internal::EnableIfForwardIterator<It>> | |
bool | try_assign (It start, It finish) |
bool | try_assign (const std::initializer_list< value_type > &list) |
template<typename... Args> | |
std::optional< iterator > | try_emplace (const_iterator pos, Args &&... args) |
template<typename... Args> | |
std::optional< typename GenericDeque< Derived, ValueType, CountAndCapacityType >::iterator > | try_emplace (const_iterator pos, Args &&... args) |
template<typename... Args> | |
bool | try_emplace_back (Args &&... args) |
template<typename... Args> | |
bool | try_emplace_front (Args &&... args) |
std::optional< iterator > | try_insert (const_iterator pos, const value_type &value) |
std::optional< iterator > | try_insert (const_iterator pos, value_type &&value) |
std::optional< iterator > | try_insert (const_iterator pos, size_type count, const value_type &value) |
template<typename ForwardIt , typename = containers::internal::EnableIfForwardIterator<ForwardIt>> | |
std::optional< iterator > | try_insert (const_iterator pos, ForwardIt first, ForwardIt last) |
std::optional< iterator > | try_insert (const_iterator pos, std::initializer_list< value_type > ilist) |
template<typename ForwardIt , typename > | |
std::optional< typename GenericDeque< Derived, ValueType, CountAndCapacityType >::iterator > | try_insert (const_iterator pos, ForwardIt first, ForwardIt last) |
bool | try_push_back (const value_type &value) |
bool | try_push_back (value_type &&value) |
bool | try_push_front (const value_type &value) |
bool | try_push_front (value_type &&value) |
bool | try_resize (size_type new_size) |
bool | try_resize (size_type new_size, const value_type &value) |
![]() | |
GenericDeque (const GenericDeque &)=delete | |
GenericDeque (GenericDeque &&)=delete | |
GenericDeque & | operator= (const GenericDeque &)=delete |
GenericDeque && | operator= (GenericDeque &&)=delete |
void | assign (size_type count, const value_type &value) |
Sets the contents to count copies of value . Crashes if cannot fit. | |
template<typename It , int & ..., typename = containers::internal::EnableIfInputIterator<It>> | |
void | assign (It start, It finish) |
void | assign (const std::initializer_list< value_type > &list) |
Sets contents to copies of the items from the list. Crashes if cannot fit. | |
constexpr reference | at (size_type index) |
constexpr const_reference | at (size_type index) const |
constexpr reference | operator[] (size_type index) |
constexpr const_reference | operator[] (size_type index) const |
constexpr reference | front () |
constexpr const_reference | front () const |
constexpr reference | back () |
constexpr const_reference | back () const |
constexpr std::pair< span< const value_type >, span< const value_type > > | contiguous_data () const |
Provides access to the valid data in a contiguous form. | |
constexpr std::pair< span< value_type >, span< value_type > > | contiguous_data () |
constexpr iterator | begin () noexcept |
constexpr const_iterator | begin () const noexcept |
constexpr const_iterator | cbegin () const noexcept |
constexpr iterator | end () noexcept |
constexpr const_iterator | end () const noexcept |
constexpr const_iterator | cend () const noexcept |
void | clear () |
iterator | erase (const_iterator pos) |
Erases the item at pos , which must be a dereferenceable iterator. | |
iterator | erase (const_iterator first, const_iterator last) |
void | push_back (const value_type &value) |
void | push_back (value_type &&value) |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
void | pop_back () |
void | push_front (const value_type &value) |
void | push_front (value_type &&value) |
template<typename... Args> | |
void | emplace_front (Args &&... args) |
void | pop_front () |
template<typename... Args> | |
iterator | emplace (const_iterator pos, Args &&... args) |
iterator | insert (const_iterator pos, const value_type &value) |
iterator | insert (const_iterator pos, value_type &&value) |
iterator | insert (const_iterator pos, size_type count, const value_type &value) |
template<typename InputIt , typename = containers::internal::EnableIfInputIterator<InputIt>> | |
iterator | insert (const_iterator pos, InputIt first, InputIt last) |
iterator | insert (const_iterator pos, std::initializer_list< value_type > ilist) |
void | resize (size_type new_size) |
void | resize (size_type new_size, const value_type &value) |
template<typename... Args> | |
std::optional< typename GenericDeque< Derived, ValueType, CountAndCapacityType >::iterator > | try_emplace (const_iterator pos, Args &&... args) |
template<typename ForwardIt , typename > | |
std::optional< typename GenericDeque< Derived, ValueType, CountAndCapacityType >::iterator > | try_insert (const_iterator pos, ForwardIt first, ForwardIt last) |
constexpr size_type | capacity () const noexcept |
Returns the maximum number of elements in the deque. | |
constexpr bool | empty () const noexcept |
constexpr size_type | size () const noexcept |
Returns the number of elements in the deque. | |
![]() | |
constexpr bool | empty () const noexcept |
constexpr size_type | size () const noexcept |
Returns the number of elements in the deque. | |
constexpr size_type | capacity () const noexcept |
Returns the maximum number of elements in the deque. | |
Friends | |
template<typename , typename > | |
class | DynamicVector |
Additional Inherited Members | |
![]() | |
constexpr | GenericDeque (size_type initial_capacity) noexcept |
Derived & | operator= (const std::initializer_list< value_type > &list) |
template<typename T , typename = containers::internal::EnableIfIterable<T>> | |
Derived & | operator= (const T &other) |
bool | try_assign (size_type count, const value_type &value) |
template<typename It , int & ..., typename = containers::internal::EnableIfForwardIterator<It>> | |
bool | try_assign (It start, It finish) |
bool | try_assign (const std::initializer_list< value_type > &list) |
template<typename... Args> | |
std::optional< iterator > | try_emplace (const_iterator pos, Args &&... args) |
std::optional< iterator > | try_insert (const_iterator pos, const value_type &value) |
std::optional< iterator > | try_insert (const_iterator pos, value_type &&value) |
std::optional< iterator > | try_insert (const_iterator pos, size_type count, const value_type &value) |
template<typename ForwardIt , typename = containers::internal::EnableIfForwardIterator<ForwardIt>> | |
std::optional< iterator > | try_insert (const_iterator pos, ForwardIt first, ForwardIt last) |
std::optional< iterator > | try_insert (const_iterator pos, std::initializer_list< value_type > ilist) |
bool | try_push_back (const value_type &value) |
bool | try_push_back (value_type &&value) |
template<typename... Args> | |
bool | try_emplace_back (Args &&... args) |
bool | try_push_front (const value_type &value) |
bool | try_push_front (value_type &&value) |
template<typename... Args> | |
bool | try_emplace_front (Args &&... args) |
bool | try_resize (size_type new_size) |
bool | try_resize (size_type new_size, const value_type &value) |
![]() | |
CountAndCapacityType & | count_and_capacity () noexcept |
constexpr void | MoveAssignIndices (GenericDequeBase &other) noexcept |
void | SwapIndices (GenericDequeBase &other) noexcept |
bool | CanExtendBuffer () const |
bool | CanShrinkBuffer () const |
void | HandleNewBuffer (size_type new_capacity) |
void | HandleExtendedBuffer (size_type new_capacity) |
void | HandleShrunkBuffer (size_type new_capacity) |
Double-ended queue, similar to std::deque
, but optimized for embedded.
Key features of pw::DynamicDeque
.
pw::Allocator
for memory operations.std::deque
API, but adds try_*
versions of operations that crash on allocation failure.assign()
& try_assign()
.push_front()
& try_push_front()
, push_back()
& try_push_back()
emplace_front()
& try_emplace_front()
, emplace_back()
& try_emplace_back()
resize()
& try_resize()
.reserve()
/try_reserve()
, reserve_exact()
/try_reserve_exact()
, and
shrink_to_fit()` to manage memory usage.constexpr
constructible.size_type
of uint8_t
or uint16_t
.pw::Allocator::Resize()
when possible to maximize efficiency.
|
inlineconstexprnoexcept |
Constructs an empty DynamicDeque
. No memory is allocated.
Since allocations can fail, initialization in the constructor is not supported.
|
inlineconstexprnoexcept |
Move construction/assignment is supported since it cannot fail. Copy construction/assignment is not supported. Can use assign()
/try_assign()
instead.
|
inline |
Replaces the container with copies of items from an initializer list. Does nothing if unable to accommodate all items.
bool pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >::try_assign | ( | It | start, |
It | finish | ||
) |
Replaces the container with copies of items from an iterator. Does nothing if unable to accommodate all items.
try_assign()
requires a forward iterator so that the capacity can be checked upfront to avoid partial assignments. Input iterators are only suitable for one pass, so could be exhausted by a std::distance
check.
bool pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >::try_assign | ( | size_type | count, |
const value_type & | value | ||
) |
Attempts to replace the contents with count
copies of value
. If count <blockquote>‍capacity()
and allocation is supported, attempts to allocate to
increase capacity. Does nothing if unable to accommodate count
items.
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >::try_emplace | ( | const_iterator | pos, |
Args &&... | args | ||
) |
Tries to construct an item in place at pos
.
std::optional
iterator to the emplaced item. If memory allocation fails, returns std::nullopt
and the container is left unchanged.
|
inline |
Tries to insert a copy of an item at pos
.
std::optional
iterator to the inserted item. If memory allocation fails, returns std::nullopt
and the container is left unchanged. std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >::try_insert | ( | const_iterator | pos, |
ForwardIt | first, | ||
ForwardIt | last | ||
) |
Tries to insert the contents of an iterator at pos
.
std::optional
iterator to the first inserted item. If memory allocation fails, returns std::nullopt
and the container is left unchanged. std::optional< typename GenericDeque< Derived, ValueType, CountAndCapacityType >::iterator > pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >::try_insert | ( | const_iterator | pos, |
size_type | count, | ||
const value_type & | value | ||
) |
Tries to insert count
copies of value
at pos
.
std::optional
iterator to the first inserted item. If memory allocation fails, returns std::nullopt
and the container is left unchanged.
|
inline |
Tries to insert an initializer list at pos
.
std::optional
iterator to the first inserted item. If memory allocation fails, returns std::nullopt
and the container is left unchanged.
|
inline |
Tries to insert an item at pos
using move semanatics.
std::optional
iterator to the inserted item. If memory allocation fails, returns std::nullopt
and the container is left unchanged. bool pw::DynamicDeque< ValueType, SizeType >::try_reserve | ( | size_type | new_capacity | ) |
Attempts to increase capacity()
to at least new_capacity
, allocating memory if needed. Does nothing if new_capacity
is less than or equal to capacity()
. Iterators are invalidated if allocation occurs.
try_reserve
may increase the capacity to be larger than new_capacity
, with the same behavior as if the size were increased to new_capacity
. To increase the capacity to a precise value, use try_reserve_exact()
.
capacity()
was already large enough; false if allocation failed
|
inline |
Attempts to increase capacity()
to new_capacity
, allocating memory if needed. Does nothing if new_capacity
is less than or equal to capacity()
.
This differs from try_reserve()
, which may reserve space for more than new_capacity
.
capacity()
was already large enough; false if allocation failed