C/C++ API Reference
Loading...
Searching...
No Matches
pw::DynamicDeque< ValueType, SizeType > Class Template Reference

Overview

template<typename ValueType, typename SizeType = uint16_t>
class pw::DynamicDeque< ValueType, SizeType >

Double-ended queue, similar to std::deque, but optimized for embedded.

Key features of pw::DynamicDeque.

  • Uses a pw::Allocator for memory operations.
  • Provides the 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().
  • Offers reserve()/try_reserve(), reserve_exact()/try_reserve_exact(), andshrink_to_fit()` to manage memory usage.
  • Never allocates in the constructor. constexpr constructible.
  • Compact representation when used with a size_type of uint8_t or uint16_t.
  • Uses pw::Allocator::Resize() when possible to maximize efficiency.
Inheritance diagram for pw::DynamicDeque< ValueType, SizeType >:

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 = SizeType
 
using value_type = ValueType
 

Public Member Functions

constexpr DynamicDeque (Allocator &allocator) noexcept
 
 DynamicDeque (const DynamicDeque &)=delete
 
DynamicDequeoperator= (const DynamicDeque &)=delete
 
constexpr DynamicDeque (DynamicDeque &&other) noexcept
 
DynamicDequeoperator= (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_typeget_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, SizeType >::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, SizeType >::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)
 

Friends

template<typename , typename >
class DynamicVector
 

Member Function Documentation

◆ try_assign() [1/3]

template<typename ValueType , typename SizeType = uint16_t>
bool pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_assign ( const std::initializer_list< value_type > &  list)
inline

Replaces the container with copies of items from an initializer list. Does nothing if unable to accommodate all items.

◆ try_assign() [2/3]

template<typename ValueType , typename SizeType = uint16_t>
template<typename It , int & ..., typename = containers::internal::EnableIfForwardIterator<It>>
bool pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::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.

◆ try_assign() [3/3]

template<typename ValueType , typename SizeType = uint16_t>
bool pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_assign ( size_type  count,
const value_type &  value 
)

Attempts to replace the contents with count copies of value. If count <blockquote>&zwj;capacity() and allocation is supported, attempts to allocate to

increase capacity. Does nothing if unable to accommodate count items.

◆ try_emplace()

template<typename ValueType , typename SizeType = uint16_t>
template<typename... Args>
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_emplace ( const_iterator  pos,
Args &&...  args 
)

Tries to construct an item in place at pos.

Returns
an std::optional iterator to the emplaced item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

◆ try_insert() [1/5]

template<typename ValueType , typename SizeType = uint16_t>
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_insert ( const_iterator  pos,
const value_type &  value 
)
inline

Tries to insert a copy of an item at pos.

Returns
an std::optional iterator to the inserted item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

◆ try_insert() [2/5]

template<typename ValueType , typename SizeType = uint16_t>
template<typename ForwardIt , typename = containers::internal::EnableIfForwardIterator<ForwardIt>>
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_insert ( const_iterator  pos,
ForwardIt  first,
ForwardIt  last 
)

Tries to insert the contents of an iterator at pos.

Returns
an std::optional iterator to the first inserted item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

◆ try_insert() [3/5]

template<typename ValueType , typename SizeType = uint16_t>
std::optional< typename GenericDeque< Derived, ValueType, SizeType >::iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_insert ( const_iterator  pos,
size_type  count,
const value_type &  value 
)

Tries to insert count copies of value at pos.

Returns
an std::optional iterator to the first inserted item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

◆ try_insert() [4/5]

template<typename ValueType , typename SizeType = uint16_t>
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_insert ( const_iterator  pos,
std::initializer_list< value_type >  ilist 
)
inline

Tries to insert an initializer list at pos.

Returns
an std::optional iterator to the first inserted item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

◆ try_insert() [5/5]

template<typename ValueType , typename SizeType = uint16_t>
std::optional< iterator > pw::containers::internal::GenericDeque< Derived, ValueType, SizeType >::try_insert ( const_iterator  pos,
value_type &&  value 
)
inline

Tries to insert an item at pos using move semanatics.

Returns
an std::optional iterator to the inserted item. If memory allocation fails, returns std::nullopt and the container is left unchanged.

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