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

Definition

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

Provides a raw, contiguous memory based LIFO (last-in, first-out) stack.

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

raw_stack is a lightweight wrapper over std::stack 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::stack, providing stack-friendly, high-performance stack operations while maintaining the same interface as std::stack.

Template Parameters
type_tThe type of elements stored in the stack.
container_tThe underlying container used to store elements. Defaults to std::deque<type_t>.
Example
q.push(1);
q.push(2);
println(q.front()); // 2
q.pop();
println(q.front();) // 1
Provides a raw, contiguous memory based LIFO (last-in, first-out) stack.
Definition raw_stack.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 stack 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.
 
using const_reverse_iterator
 Const reverse iterator type.
 

Public Constructors

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

Public Properties

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

Public Methods

auto clear () -> void
 Removes all elements from the stack.
 
auto push (const value_type &value) -> void
 Adds a copy of the element at the back of the stack.
 
auto push (value_type &&value) -> void
 Moves the element into the back of the stack.
 
auto pop () -> void
 Removes the element at the front of the stack.
 
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_stackoperator= (const raw_stack &other)=default
 Copy assignment.
 
raw_stackoperator= (raw_stack &&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_stack< type_t, container_t >::base_type

The base STL stack type.

◆ container_type

template<class type_t, class container_t = std::deque<type_t>>
using xtd::collections::generic::helpers::raw_stack< 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_stack< 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_stack< 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_stack< 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_stack< 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_stack< type_t, container_t >::const_iterator

Const iterator type.

◆ const_reverse_iterator

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

Const reverse iterator type.

Constructor & Destructor Documentation

◆ raw_stack() [1/6]

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

Default constructor. Initializes an empty stack.

Remarks
Capacity is initialized to zero.

◆ raw_stack() [2/6]

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

Constructs an empty stack with reserved capacity.

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

◆ raw_stack() [3/6]

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

Copy constructor.

◆ raw_stack() [4/6]

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

Move constructor.

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

◆ raw_stack() [5/6]

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

Constructs a stack from a range of iterators.

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

◆ raw_stack() [6/6]

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

Constructs a stack 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_stack< type_t, container_t >::begin ( ) const -> const_iterator
inline

Gets a const iterator to the beginning of the stack.

Returns
Iterator to the beginning of the stack.

◆ capacity()

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

Gets the reserved capacity of the stack.

Returns
The reserved capacity of the stack.

◆ cbegin()

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

Gets a const iterator to the beginning of the stack.

Returns
Iterator to the beginning of the stack.

◆ cend()

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

Gets a const iterator to the end of the stack.

Returns
Iterator to the end of the stack.

◆ crbegin()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_stack< type_t, container_t >::crbegin ( ) const -> const_reverse_iterator
inline

Gets a const reverse iterator to the beginning of the stack.

Returns
Iterator to the beginning of the stack.

◆ crend()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_stack< type_t, container_t >::crend ( ) const -> const_reverse_iterator
inline

Gets a const reverse iterator to the end of the stack.

Returns
Iterator to the end of the stack.

◆ end()

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

Gets a const iterator to the end of the stack.

Returns
Iterator to the end of the stack.

◆ items() [1/2]

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

Access to the underlying base stack.

Returns
The underlying base stack.

◆ items() [2/2]

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

Access to the underlying base stack.

Returns
The underlying base stack.

◆ rbegin()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_stack< type_t, container_t >::rbegin ( ) const -> const_reverse_iterator
inline

Gets a const reverse iterator to the beginning of the stack.

Returns
Iterator to the beginning of the stack.

◆ rend()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_stack< type_t, container_t >::rend ( ) const -> const_reverse_iterator
inline

Gets a const reverse iterator to the end of the stack.

Returns
Iterator to the end of the stack.

◆ size()

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

Gets the number of elements in the stack.

Returns
The number of elements in the stack.

◆ clear()

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

Removes all elements from the stack.

◆ push() [1/2]

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

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

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_stack< type_t, container_t >::push ( value_type && value) -> void
inline

Moves the element into the back of the stack.

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_stack< type_t, container_t >::pop ( ) -> void
inline

Removes the element at the front of the stack.

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

◆ reserve()

template<class type_t, class container_t = std::deque<type_t>>
auto xtd::collections::generic::helpers::raw_stack< 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_stack< 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_stack & xtd::collections::generic::helpers::raw_stack< type_t, container_t >::operator= ( const raw_stack< type_t, container_t > & other)
default

Copy assignment.

◆ operator=() [2/2]

template<class type_t, class container_t = std::deque<type_t>>
raw_stack & xtd::collections::generic::helpers::raw_stack< type_t, container_t >::operator= ( raw_stack< 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_stack< 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_stack< type_t, container_t >::operator base_type & ( )
inlinenoexcept

Cast to base_type.


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