libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Deque< T > Class Template Reference

Double-ended queue container wrapping std::deque. More...

#include <deque.h>

Public Types

using Ptr = SharedPtr< Deque >
 Shared pointer type for Deque.
 
using Data = std::deque< T >
 Underlying std::deque storage type.
 
using Value = T
 Value type.
 
using Iterator = typename Data::iterator
 Mutable forward iterator.
 
using ConstIterator = typename Data::const_iterator
 Const forward iterator.
 
using RevIterator = typename Data::reverse_iterator
 Mutable reverse iterator.
 
using ConstRevIterator = typename Data::const_reverse_iterator
 Const reverse iterator.
 

Public Member Functions

 Deque ()=default
 Default constructor. Creates an empty deque.
 
 Deque (const Deque &other)
 Copy constructor.
 
 Deque (Deque &&other) noexcept
 Move constructor.
 
 Deque (std::initializer_list< T > initList)
 Constructs a deque from an initializer list.
 
 ~Deque ()=default
 Destructor.
 
Dequeoperator= (const Deque &other)
 Copy assignment operator.
 
Dequeoperator= (Deque &&other) noexcept
 Move assignment operator.
 
Iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
ConstIterator begin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator constBegin () const noexcept
 Returns a const iterator to the first element.
 
Iterator end () noexcept
 Returns a mutable iterator to one past the last element.
 
ConstIterator end () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator cend () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator constEnd () const noexcept
 Returns a const iterator to one past the last element.
 
RevIterator rbegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
RevIterator revBegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
ConstRevIterator crbegin () const noexcept
 Returns a const reverse iterator to the last element.
 
ConstRevIterator constRevBegin () const noexcept
 Returns a const reverse iterator to the last element.
 
RevIterator rend () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
RevIterator revEnd () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
ConstRevIterator crend () const noexcept
 Returns a const reverse iterator to one before the first element.
 
ConstRevIterator constRevEnd () const noexcept
 Returns a const reverse iterator to one before the first element.
 
Tat (size_t index)
 Returns a reference to the element at index with bounds checking.
 
const Tat (size_t index) const
 Returns a reference to the element at index with bounds checking.
 
Toperator[] (size_t index)
 Returns a reference to the element at index without bounds checking.
 
const Toperator[] (size_t index) const
 Returns a reference to the element at index without bounds checking.
 
Tfront ()
 Returns a reference to the first element.
 
const Tfront () const
 Returns a reference to the first element.
 
Tback ()
 Returns a reference to the last element.
 
const Tback () const
 Returns a reference to the last element.
 
bool isEmpty () const noexcept
 Returns true if the deque has no elements.
 
size_t size () const noexcept
 Returns the number of elements.
 
void pushToFront (const T &value)
 Pushes an item onto the front of the deque.
 
void pushToFront (T &&value)
 Pushes an item onto the front of the deque (move overload).
 
void pushToBack (const T &value)
 Pushes an item onto the back of the deque.
 
void pushToBack (T &&value)
 Pushes an item onto the back of the deque (move overload).
 
T popFromFront ()
 Removes and returns the first element.
 
T popFromBack ()
 Removes and returns the last element.
 
void clear () noexcept
 Removes all elements.
 
void swap (Deque &other) noexcept
 Swaps contents with another deque.
 
template<typename Func >
void forEach (Func &&func) const
 Calls func for every element.
 

Friends

bool operator== (const Deque &lhs, const Deque &rhs)
 Returns true if both deques have identical contents.
 
bool operator!= (const Deque &lhs, const Deque &rhs)
 Returns true if the deques differ.
 

Detailed Description

template<typename T>
class Deque< T >

Double-ended queue container wrapping std::deque.

Provides a Qt-inspired API over std::deque with consistent naming

  • Example
    dq.pushToFront(0);
    int first = dq.front(); // 0
    dq.popFromFront();
    Dynamic array container wrapping std::vector.
    Definition list.h:40
    T & front()
    Returns a reference to the first element.
    Definition list.h:266
    void pushToBack(const T &value)
    Pushes an item onto the back of the list.
    Definition list.h:455
    conventions matching the rest of libpromeki.
    Template Parameters
    TElement type.

Constructor & Destructor Documentation

◆ Deque()

template<typename T >
Deque< T >::Deque ( std::initializer_list< T initList)
inline

Constructs a deque from an initializer list.

Parameters
initListBrace-enclosed list of values.

Member Function Documentation

◆ at() [1/2]

template<typename T >
T & Deque< T >::at ( size_t  index)
inline

Returns a reference to the element at index with bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ at() [2/2]

template<typename T >
const T & Deque< T >::at ( size_t  index) const
inline

Returns a reference to the element at index with bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ back()

template<typename T >
const T & Deque< T >::back ( ) const
inline

Returns a reference to the last element.

◆ constBegin()

template<typename T >
ConstIterator Deque< T >::constBegin ( ) const
inlinenoexcept

Returns a const iterator to the first element.

◆ constEnd()

template<typename T >
ConstIterator Deque< T >::constEnd ( ) const
inlinenoexcept

Returns a const iterator to one past the last element.

◆ constRevBegin()

template<typename T >
ConstRevIterator Deque< T >::constRevBegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the last element.

◆ constRevEnd()

template<typename T >
ConstRevIterator Deque< T >::constRevEnd ( ) const
inlinenoexcept

Returns a const reverse iterator to one before the first element.

◆ forEach()

template<typename T >
template<typename Func >
void Deque< T >::forEach ( Func &&  func) const
inline

Calls func for every element.

Template Parameters
FuncCallable with signature void(const T &).
Parameters
funcThe function to invoke.

◆ front()

template<typename T >
const T & Deque< T >::front ( ) const
inline

Returns a reference to the first element.

◆ operator[]() [1/2]

template<typename T >
T & Deque< T >::operator[] ( size_t  index)
inline

Returns a reference to the element at index without bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ operator[]() [2/2]

template<typename T >
const T & Deque< T >::operator[] ( size_t  index) const
inline

Returns a reference to the element at index without bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ popFromBack()

template<typename T >
T Deque< T >::popFromBack ( )
inline

Removes and returns the last element.

Returns
The removed element.

◆ popFromFront()

template<typename T >
T Deque< T >::popFromFront ( )
inline

Removes and returns the first element.

Returns
The removed element.

◆ pushToBack() [1/2]

template<typename T >
void Deque< T >::pushToBack ( const T value)
inline

Pushes an item onto the back of the deque.

Parameters
valueThe value to append.

◆ pushToBack() [2/2]

template<typename T >
void Deque< T >::pushToBack ( T &&  value)
inline

Pushes an item onto the back of the deque (move overload).

Parameters
valueThe value to move-append.

◆ pushToFront() [1/2]

template<typename T >
void Deque< T >::pushToFront ( const T value)
inline

Pushes an item onto the front of the deque.

Parameters
valueThe value to prepend.

◆ pushToFront() [2/2]

template<typename T >
void Deque< T >::pushToFront ( T &&  value)
inline

Pushes an item onto the front of the deque (move overload).

Parameters
valueThe value to move-prepend.

◆ revBegin()

template<typename T >
RevIterator Deque< T >::revBegin ( )
inlinenoexcept

Returns a mutable reverse iterator to the last element.

◆ revEnd()

template<typename T >
RevIterator Deque< T >::revEnd ( )
inlinenoexcept

Returns a mutable reverse iterator to one before the first element.

◆ swap()

template<typename T >
void Deque< T >::swap ( Deque< T > &  other)
inlinenoexcept

Swaps contents with another deque.

Parameters
otherThe deque to swap with.

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