xtd 0.2.0
Loading...
Searching...
No Matches
xtd::collections::generic::helpers::raw_queue< type_t, container_t > Class Template Referencefinal
Inheritance diagram for xtd::collections::generic::helpers::raw_queue< type_t, container_t >:

Definition

template<class type_t, class container_t = std::deque<type_t>>
class xtd::collections::generic::helpers::raw_queue< type_t, container_t >

Provides a raw, contiguous memory based FIFO (first-in, first-out) queue.

Header
#include <xtd/collections/generic/helpers/raw_queue>
Namespace
xtd::collections::generic::helpers
Library
xtd.core

raw_queue is a lightweight wrapper over std::queue that exposes additional methods such as capacity control, iterators, reserve, and shrink_to_fit. It is intended as a base class for xtd::collections::generic::queue, providing stack-friendly, high-performance queue operations while maintaining the same interface as std::queue.

Template Parameters
type_tThe type of elements stored in the queue.
container_tThe underlying container used to store elements. Defaults to std::deque<type_t>.
Example
q.push(1);
q.push(2);
println(q.front()); // 1
q.pop();
println(q.front();) // 2
Provides a raw, contiguous memory based FIFO (first-in, first-out) queue.
Definition raw_queue.hpp:43
@ q
The Q key.
Definition console_key.hpp:120
void println()
Writes the current line terminator to the standard output stream using the specified format informati...
Definition println.hpp:167

Public Aliases

using base_type
 The base STL queue type.
 
using container_type
 The underlying container type.
 
using value_type
 Type of elements stored.
 
using size_type
 Unsigned integer type used for size and capacity.
 
using reference
 Reference to element type.
 
using const_reference
 Const reference to element type.
 
using const_iterator
 Const iterator type.
 

Public Constructors

 raw_queue ()
 Default constructor. Initializes an empty queue.
 
 raw_queue (size_type capacity)
 Constructs an empty queue with reserved capacity.
 
 raw_queue (const raw_queue &other)
 Copy constructor.
 
 raw_queue (raw_queue &&other)
 Move constructor.
 
template<class input_iterator_t>
 raw_queue (input_iterator_t first, input_iterator_t last)
 Constructs a queue from a range of iterators.
 
template<class allocator_t>
 raw_queue (const allocator_t &alloc)
 Constructs a queue with a specific allocator.
 

Public Properties

auto begin () const -> const_iterator
 Gets a const iterator to the beginning of the queue.
 
auto capacity () const noexcept -> size_type
 Gets the reserved capacity of the queue.
 
auto cbegin () const -> const_iterator
 Gets a const iterator to the beginning of the queue.
 
auto cend () const -> const_iterator
 Gets a const iterator to the end of the queue.
 
auto end () const -> const_iterator
 Gets a const iterator to the end of the queue.
 
auto items () noexcept -> base_type &
 Access to the underlying base queue.
 
auto items () const noexcept -> const base_type &
 Access to the underlying base queue.
 
auto size () const noexcept -> size_type
 Gets the number of elements in the queue.
 

Public Methods

auto clear () -> void
 Removes all elements from the queue.
 
auto push (const value_type &value) -> void
 Adds a copy of the element at the back of the queue.
 
auto push (value_type &&value) -> void
 Moves the element into the back of the queue.
 
auto pop () -> void
 Removes the element at the front of the queue.
 
auto reserve (size_type count) -> void
 Reserves storage to hold at least count elements.
 
auto shrink_to_fit () -> void
 Reduces capacity to fit the current size.
 

Public Operators

raw_queueoperator= (const raw_queue &other)=default
 Copy assignment.
 
raw_queueoperator= (raw_queue &&other)=default
 Move assignment.
 
 operator const base_type & () const noexcept
 Cast to const base_type.
 
 operator base_type & () noexcept
 Cast to base_type.
 

Member Typedef Documentation

◆ base_type

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::base_type

The base STL queue type.

◆ container_type

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::container_type

The underlying container type.

◆ value_type

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::value_type

Type of elements stored.

◆ size_type

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::size_type

Unsigned integer type used for size and capacity.

◆ reference

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::reference

Reference to element type.

◆ const_reference

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::const_reference

Const reference to element type.

◆ const_iterator

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_queue< type_t, container_t >::const_iterator

Const iterator type.

Constructor & Destructor Documentation

◆ raw_queue() [1/6]

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( )
inline

Default constructor. Initializes an empty queue.

Remarks
Capacity is initialized to zero.

◆ raw_queue() [2/6]

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( size_type capacity)
inlineexplicit

Constructs an empty queue with reserved capacity.

Parameters
capacityThe initial capacity to reserve.
Remarks
Internally resizes the container to optimize future push operations.

◆ raw_queue() [3/6]

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( const raw_queue< type_t, container_t > & other)
inline

Copy constructor.

◆ raw_queue() [4/6]

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( raw_queue< type_t, container_t > && other)
inline

Move constructor.

Parameters
otherAnother raw_queue to move from.
Note
The moved-from queue will be empty after this operation.

◆ raw_queue() [5/6]

template<class type_t, class container_t = std::deque<type_t>>
template<class input_iterator_t>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( input_iterator_t first,
input_iterator_t last )
inline

Constructs a queue from a range of iterators.

Template Parameters
input_iterator_tInput iterator type.
Parameters
firstIterator to the first element.
lastIterator past the last element.

◆ raw_queue() [6/6]

template<class type_t, class container_t = std::deque<type_t>>
template<class allocator_t>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::raw_queue ( const allocator_t & alloc)
inlineexplicit

Constructs a queue with a specific allocator.

Member Function Documentation

◆ begin()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::begin ( ) const -> const_iterator
inline

Gets a const iterator to the beginning of the queue.

Returns
Iterator to the beginning of the queue.

◆ capacity()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::capacity ( ) const -> size_type
inlinenoexcept

Gets the reserved capacity of the queue.

Returns
The reserved capacity of the queue.

◆ cbegin()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::cbegin ( ) const -> const_iterator
inline

Gets a const iterator to the beginning of the queue.

Returns
Iterator to the beginning of the queue.

◆ cend()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::cend ( ) const -> const_iterator
inline

Gets a const iterator to the end of the queue.

Returns
Iterator to the end of the queue.

◆ end()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::end ( ) const -> const_iterator
inline

Gets a const iterator to the end of the queue.

Returns
Iterator to the end of the queue.

◆ items() [1/2]

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::items ( ) -> base_type&
inlinenoexcept

Access to the underlying base queue.

Returns
The underlying base queue.

◆ items() [2/2]

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::items ( ) const -> const base_type&
inlinenoexcept

Access to the underlying base queue.

Returns
The underlying base queue.

◆ size()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::size ( ) const -> size_type
inlinenoexcept

Gets the number of elements in the queue.

Returns
The number of elements in the queue.

◆ clear()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::clear ( ) -> void
inline

Removes all elements from the queue.

◆ push() [1/2]

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::push ( const value_type & value) -> void
inline

Adds a copy of the element at the back of the queue.

Parameters
valueThe value to push.
Remarks
Capacity is automatically increased if needed.

◆ push() [2/2]

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::push ( value_type && value) -> void
inline

Moves the element into the back of the queue.

Parameters
valueThe value to push.
Remarks
Capacity is automatically increased if needed.

◆ pop()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::pop ( ) -> void
inline

Removes the element at the front of the queue.

Warning
Calling pop() on an empty queue is undefined behavior.

◆ reserve()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::reserve ( size_type count) -> void
inline

Reserves storage to hold at least count elements.

Parameters
countNumber of elements to reserve space for.
Remarks
This allows you to optimize push operations by pre-allocating memory.

◆ shrink_to_fit()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_queue< type_t, container_t >::shrink_to_fit ( ) -> void
inline

Reduces capacity to fit the current size.

Remarks
Use this to minimize memory usage after many pop operations.

◆ operator=() [1/2]

template<class type_t, class container_t = std::deque<type_t>>
raw_queue & xtd::collections::generic::helpers::raw_queue< type_t, container_t >::operator= ( const raw_queue< type_t, container_t > & other)
default

Copy assignment.

◆ operator=() [2/2]

template<class type_t, class container_t = std::deque<type_t>>
raw_queue & xtd::collections::generic::helpers::raw_queue< type_t, container_t >::operator= ( raw_queue< type_t, container_t > && other)
default

Move assignment.

◆ operator const base_type &()

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::operator const base_type & ( ) const
inlinenoexcept

Cast to const base_type.

◆ operator base_type &()

template<class type_t, class container_t = std::deque<type_t>>
xtd::collections::generic::helpers::raw_queue< type_t, container_t >::operator base_type & ( )
inlinenoexcept

Cast to base_type.


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