Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
pw::DynamicDeque< ValueType, SizeType > Class Template Reference
Inheritance diagram for pw::DynamicDeque< ValueType, SizeType >:
pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType > pw::containers::internal::GenericDequeBase< CountAndCapacityType >

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
 
- Public Types inherited from pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >
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 >
 
- Public Types inherited from pw::containers::internal::GenericDequeBase< CountAndCapacityType >
using size_type = typename CountAndCapacityType::size_type
 

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, 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)
 
- Public Member Functions inherited from pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >
 GenericDeque (const GenericDeque &)=delete
 
 GenericDeque (GenericDeque &&)=delete
 
GenericDequeoperator= (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.
 
- Public Member Functions inherited from pw::containers::internal::GenericDequeBase< CountAndCapacityType >
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

- Protected Member Functions inherited from pw::containers::internal::GenericDeque< Derived, ValueType, CountAndCapacityType >
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)
 
- Protected Member Functions inherited from pw::containers::internal::GenericDequeBase< CountAndCapacityType >
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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DynamicDeque() [1/2]

template<typename ValueType , typename SizeType = uint16_t>
constexpr pw::DynamicDeque< ValueType, SizeType >::DynamicDeque ( Allocator allocator)
inlineconstexprnoexcept

Constructs an empty DynamicDeque. No memory is allocated.

Since allocations can fail, initialization in the constructor is not supported.

◆ DynamicDeque() [2/2]

template<typename ValueType , typename SizeType = uint16_t>
constexpr pw::DynamicDeque< ValueType, SizeType >::DynamicDeque ( DynamicDeque< ValueType, SizeType > &&  other)
inlineconstexprnoexcept

Move construction/assignment is supported since it cannot fail. Copy construction/assignment is not supported. Can use assign()/try_assign() instead.

Member Function Documentation

◆ try_assign() [1/3]

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

◆ try_assign() [3/3]

template<typename ValueType , typename SizeType = uint16_t>
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>&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, CountAndCapacityType >::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, CountAndCapacityType >::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, CountAndCapacityType >::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, 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.

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, CountAndCapacityType >::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, CountAndCapacityType >::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.

◆ try_reserve()

template<typename ValueType , typename SizeType >
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().

Returns
true if allocation succeeded or capacity() was already large enough; false if allocation failed

◆ try_reserve_exact()

template<typename ValueType , typename SizeType = uint16_t>
bool pw::DynamicDeque< ValueType, SizeType >::try_reserve_exact ( size_type  new_capacity)
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.

Returns
true if allocation succeeded or capacity() was already large enough; false if allocation failed

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