StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Queue< T > Class Template Referencefinal

FIFO sequence stored on Base's heap. More...

#include <StormByte/safe/queue.hxx>

Public Types

using value_type = T
 Element type.
using container_type = Vector<T>
 Underlying Base-owned sequence.
using size_type = Size
 Element count. Size, not std::size_t.
using difference_type = std::ptrdiff_t
 Iterator distance type.
using reference = T&
 Mutable element reference.
using const_reference = const T&
 Read-only element reference.
using iterator = typename Vector<T>::iterator
 Mutable iterator, front to back.
using const_iterator = typename Vector<T>::const_iterator
 Read-only iterator, front to back.

Public Member Functions

 Queue () noexcept
 Construct an empty queue.
STORMBYTE_FORCE_INLINE Queue (const std::queue< T > &values)
 Copy a caller-owned STL queue.
STORMBYTE_FORCE_INLINE Queue (std::queue< T > &&values)
 Move elements from a caller-owned STL queue and leave it empty.
 Queue (const container_type &values)
 Copy the underlying sequence.
 Queue (container_type &&values) noexcept
 Take the underlying sequence.
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, T>
STORMBYTE_FORCE_INLINE Queue (std::from_range_t, R &&range)
 Copy the elements of range, in order.
 Queue (const Queue &other)
 Copy every element into a new Base block.
 Queue (Queue &&other) noexcept
 Take the block.
 ~Queue () noexcept
 Destroy every element and release the block.
Queue & operator= (const Queue &other)
 Copy-assign.
Queue & operator= (Queue &&other) noexcept
 Move-assign.
STORMBYTE_FORCE_INLINE Queue & operator= (const std::queue< T > &values)
 Copy-assign a caller-owned STL queue.
STORMBYTE_FORCE_INLINE Queue & operator= (std::queue< T > &&values)
 Move-assign a caller-owned STL queue and leave it empty.
iterator begin () noexcept
 Return a mutable iterator to the front.
iterator end () noexcept
 Return the mutable end iterator.
const_iterator begin () const noexcept
 Return a read-only iterator to the front.
const_iterator end () const noexcept
 Return the read-only end iterator.
const_iterator cbegin () const noexcept
 Return a read-only iterator to the front.
const_iterator cend () const noexcept
 Return the read-only end iterator.
bool empty () const noexcept
 Test whether the queue is empty.
size_type size () const noexcept
 Return the element count.
reference front ()
 Return the front element.
const_reference front () const
 Return the front element.
reference back ()
 Return the back element.
const_reference back () const
 Return the back element.
void push (const T &value)
 Append a copy.
void push (T &&value)
 Append a moved value.
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, T>
STORMBYTE_FORCE_INLINE void push_range (R &&range)
 Append a copy of range, in order.
template<class... Args>
reference emplace (Args &&... args)
 Construct an element at the back.
void pop ()
 Remove the front element.
iterator erase (const_iterator position)
 Erase one element.
iterator erase (const_iterator first, const_iterator last)
 Erase a half-open range.
void swap (Queue &other) noexcept
 Exchange blocks.
bool operator== (const Queue &other) const
 Compare elements in FIFO order.
STORMBYTE_FORCE_INLINE std::strong_ordering operator<=> (const Queue &other) const
 Order queues lexicographically.
bool operator< (const Queue &other) const
 Order queues lexicographically.
bool operator<= (const Queue &other) const
 Order queues lexicographically.
bool operator> (const Queue &other) const
 Order queues lexicographically.
bool operator>= (const Queue &other) const
 Order queues lexicographically.
STORMBYTE_FORCE_INLINE operator std::queue< T > () const
 Copy the elements into caller-owned STL storage.

Detailed Description

template<Type::SafeValue T>
class StormByte::Safe::Queue< T >

FIFO sequence stored on Base's heap.

Template Parameters
TSafe value.

Elements live in a Vector. A move from std::queue moves each element and pops the source in the caller, so the deque buffer is released by the caller's CRT. Iterators walk the queue in FIFO order.

Member Typedef Documentation

◆ const_iterator

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::const_iterator = typename Vector<T>::const_iterator

Read-only iterator, front to back.

◆ const_reference

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::const_reference = const T&

Read-only element reference.

◆ container_type

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::container_type = Vector<T>

Underlying Base-owned sequence.

◆ difference_type

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::difference_type = std::ptrdiff_t

Iterator distance type.

◆ iterator

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::iterator = typename Vector<T>::iterator

Mutable iterator, front to back.

◆ reference

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::reference = T&

Mutable element reference.

◆ size_type

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::size_type = Size

Element count. Size, not std::size_t.

◆ value_type

template<Type::SafeValue T>
using StormByte::Safe::Queue< T >::value_type = T

Element type.

Constructor & Destructor Documentation

◆ Queue() [1/8]

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::Queue ( )
noexcept

Construct an empty queue.

◆ Queue() [2/8]

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE StormByte::Safe::Queue< T >::Queue ( const std::queue< T > & values)
inlineexplicit

Copy a caller-owned STL queue.

Its state is unchanged.

Parameters
valuesSource.
Exceptions
AllocationErrorThe block could not be allocated.

◆ Queue() [3/8]

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE StormByte::Safe::Queue< T >::Queue ( std::queue< T > && values)
inlineexplicit

Move elements from a caller-owned STL queue and leave it empty.

Parameters
valuesSource. Empty before this function returns.
Exceptions
AllocationErrorThe block could not be allocated.

◆ Queue() [4/8]

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::Queue ( const container_type & values)
explicit

Copy the underlying sequence.

Parameters
valuesSource. Unchanged.
Exceptions
AllocationErrorThe block could not be allocated.

◆ Queue() [5/8]

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::Queue ( container_type && values)
explicitnoexcept

Take the underlying sequence.

values is left empty.

Parameters
valuesSource.

◆ Queue() [6/8]

template<Type::SafeValue T>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, T>
STORMBYTE_FORCE_INLINE StormByte::Safe::Queue< T >::Queue ( std::from_range_t ,
R && range )
inlineexplicit

Copy the elements of range, in order.

Template Parameters
RInput range of value_type.
Parameters
rangeSource. Instantiated in the caller.
Exceptions
AllocationErrorThe block could not be allocated.

◆ Queue() [7/8]

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::Queue ( const Queue< T > & other)

Copy every element into a new Base block.

Parameters
otherSource.
Exceptions
AllocationErrorThe block could not be allocated.

◆ Queue() [8/8]

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::Queue ( Queue< T > && other)
noexcept

Take the block.

other is left empty.

Parameters
otherSource.

◆ ~Queue()

template<Type::SafeValue T>
StormByte::Safe::Queue< T >::~Queue ( )
noexcept

Destroy every element and release the block.

Member Function Documentation

◆ back() [1/2]

template<Type::SafeValue T>
reference StormByte::Safe::Queue< T >::back ( )

Return the back element.

Returns
Back element. Valid until it is erased or the queue reallocates.
Exceptions
OutOfBoundsErrorThe queue is empty.

◆ back() [2/2]

template<Type::SafeValue T>
const_reference StormByte::Safe::Queue< T >::back ( ) const

Return the back element.

Returns
Back element. Valid until it is erased or the queue reallocates.
Exceptions
OutOfBoundsErrorThe queue is empty.

◆ begin() [1/2]

template<Type::SafeValue T>
const_iterator StormByte::Safe::Queue< T >::begin ( ) const
noexcept

Return a read-only iterator to the front.

Returns
Read-only iterator.

◆ begin() [2/2]

template<Type::SafeValue T>
iterator StormByte::Safe::Queue< T >::begin ( )
noexcept

Return a mutable iterator to the front.

Returns
Mutable iterator.

◆ cbegin()

template<Type::SafeValue T>
const_iterator StormByte::Safe::Queue< T >::cbegin ( ) const
noexcept

Return a read-only iterator to the front.

Returns
Read-only iterator.

◆ cend()

template<Type::SafeValue T>
const_iterator StormByte::Safe::Queue< T >::cend ( ) const
noexcept

Return the read-only end iterator.

Returns
End iterator.

◆ emplace()

template<Type::SafeValue T>
template<class... Args>
reference StormByte::Safe::Queue< T >::emplace ( Args &&... args)

Construct an element at the back.

Template Parameters
ArgsConstructor argument types.
Parameters
argsArguments forwarded to T.
Returns
Reference to the new element.
Exceptions
AllocationErrorThe block could not be allocated.

◆ empty()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::empty ( ) const
noexcept

Test whether the queue is empty.

Returns
Whether no elements are queued.

◆ end() [1/2]

template<Type::SafeValue T>
const_iterator StormByte::Safe::Queue< T >::end ( ) const
noexcept

Return the read-only end iterator.

Returns
End iterator.

◆ end() [2/2]

template<Type::SafeValue T>
iterator StormByte::Safe::Queue< T >::end ( )
noexcept

Return the mutable end iterator.

Returns
End iterator.

◆ erase() [1/2]

template<Type::SafeValue T>
iterator StormByte::Safe::Queue< T >::erase ( const_iterator first,
const_iterator last )

Erase a half-open range.

Parameters
firstFirst element to erase.
lastPast-the-end element.
Returns
Iterator following the erased range.

◆ erase() [2/2]

template<Type::SafeValue T>
iterator StormByte::Safe::Queue< T >::erase ( const_iterator position)

Erase one element.

Parameters
positionElement to erase.
Returns
Iterator following the erased element.

◆ front() [1/2]

template<Type::SafeValue T>
reference StormByte::Safe::Queue< T >::front ( )

Return the front element.

Returns
Front element. Valid until it is popped or the queue reallocates.
Exceptions
OutOfBoundsErrorThe queue is empty.

◆ front() [2/2]

template<Type::SafeValue T>
const_reference StormByte::Safe::Queue< T >::front ( ) const

Return the front element.

Returns
Front element. Valid until it is popped or the queue reallocates.
Exceptions
OutOfBoundsErrorThe queue is empty.

◆ operator std::queue< T >()

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE StormByte::Safe::Queue< T >::operator std::queue< T > ( ) const
inlineexplicit

Copy the elements into caller-owned STL storage.

Returns
A std::queue owned by the caller.

◆ operator<()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::operator< ( const Queue< T > & other) const

Order queues lexicographically.

Parameters
otherQueue to compare.
Returns
Whether this queue precedes other.

◆ operator<=()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::operator<= ( const Queue< T > & other) const

Order queues lexicographically.

Parameters
otherQueue to compare.
Returns
Whether this queue precedes or equals other.

◆ operator<=>()

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE std::strong_ordering StormByte::Safe::Queue< T >::operator<=> ( const Queue< T > & other) const

Order queues lexicographically.

Parameters
otherQueue to compare.
Returns
Ordering.

◆ operator=() [1/4]

template<Type::SafeValue T>
Queue & StormByte::Safe::Queue< T >::operator= ( const Queue< T > & other)

Copy-assign.

Parameters
otherSource.
Returns
This queue.
Exceptions
AllocationErrorThe block could not be allocated.

◆ operator=() [2/4]

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE Queue & StormByte::Safe::Queue< T >::operator= ( const std::queue< T > & values)
inline

Copy-assign a caller-owned STL queue.

Its state is unchanged.

Parameters
valuesSource.
Returns
This queue.
Exceptions
AllocationErrorThe block could not be allocated.

◆ operator=() [3/4]

template<Type::SafeValue T>
Queue & StormByte::Safe::Queue< T >::operator= ( Queue< T > && other)
noexcept

Move-assign.

other is left empty.

Parameters
otherSource.
Returns
This queue.

◆ operator=() [4/4]

template<Type::SafeValue T>
STORMBYTE_FORCE_INLINE Queue & StormByte::Safe::Queue< T >::operator= ( std::queue< T > && values)
inline

Move-assign a caller-owned STL queue and leave it empty.

Parameters
valuesSource. Empty before this function returns.
Returns
This queue.
Exceptions
AllocationErrorThe block could not be allocated.

◆ operator==()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::operator== ( const Queue< T > & other) const

Compare elements in FIFO order.

Parameters
otherQueue to compare.
Returns
Whether both queues contain the same elements.

◆ operator>()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::operator> ( const Queue< T > & other) const

Order queues lexicographically.

Parameters
otherQueue to compare.
Returns
Whether this queue follows other.

◆ operator>=()

template<Type::SafeValue T>
bool StormByte::Safe::Queue< T >::operator>= ( const Queue< T > & other) const

Order queues lexicographically.

Parameters
otherQueue to compare.
Returns
Whether this queue follows or equals other.

◆ pop()

template<Type::SafeValue T>
void StormByte::Safe::Queue< T >::pop ( )

Remove the front element.

Exceptions
OutOfBoundsErrorThe queue is empty.

◆ push() [1/2]

template<Type::SafeValue T>
void StormByte::Safe::Queue< T >::push ( const T & value)

Append a copy.

Parameters
valueValue to copy.
Exceptions
AllocationErrorThe block could not be allocated.

◆ push() [2/2]

template<Type::SafeValue T>
void StormByte::Safe::Queue< T >::push ( T && value)

Append a moved value.

Parameters
valueValue to move.
Exceptions
AllocationErrorThe block could not be allocated.

◆ push_range()

template<Type::SafeValue T>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, T>
STORMBYTE_FORCE_INLINE void StormByte::Safe::Queue< T >::push_range ( R && range)
inline

Append a copy of range, in order.

Template Parameters
RInput range of value_type.
Parameters
rangeSource. Instantiated in the caller.
Exceptions
AllocationErrorThe block could not be allocated.

◆ size()

template<Type::SafeValue T>
size_type StormByte::Safe::Queue< T >::size ( ) const
noexcept

Return the element count.

Returns
Element count.

◆ swap()

template<Type::SafeValue T>
void StormByte::Safe::Queue< T >::swap ( Queue< T > & other)
noexcept

Exchange blocks.

Does not allocate.

Parameters
otherQueue to exchange with.

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