Loading...
Searching...
No Matches
containers::Stack< T > Class Template Reference

A simple LIFO stack backed by std::vector. More...

#include <containers.hpp>

Public Member Functions

void clear ()
 Remove all elements.
 
bool empty () const
 Check if the stack is empty.
 
pop ()
 Remove and return the top element.
 
void push (const T &value)
 Push a value onto the top of the stack.
 
std::size_t size () const
 Get the number of elements.
 
const T & top () const
 Peek at the top element without removing it.
 

Detailed Description

template<typename T>
class containers::Stack< T >

A simple LIFO stack backed by std::vector.

Template Parameters
TElement type.
Note
This is intentionally simple — it demonstrates how doxyYoda renders template class documentation, not a production container.
See also
RingBuffer for a fixed-capacity alternative.
yoda::Vec2 for another template class example.

Definition at line 85 of file containers.hpp.

Member Function Documentation

◆ clear()

template<typename T>
void containers::Stack< T >::clear ( )
inline

Remove all elements.

Definition at line 126 of file containers.hpp.

126{ data_.clear(); }

◆ empty()

template<typename T>
bool containers::Stack< T >::empty ( ) const
inlinenodiscard

Check if the stack is empty.

Definition at line 120 of file containers.hpp.

120{ return data_.empty(); }

◆ pop()

template<typename T>
T containers::Stack< T >::pop ( )
inline

Remove and return the top element.

Returns
The top element.
Exceptions
BufferUnderflowif the stack is empty.
Precondition
!empty()

Definition at line 102 of file containers.hpp.

102 {
103 if (data_.empty()) throw BufferUnderflow();
104 T val = data_.back();
105 data_.pop_back();
106 return val;
107 }
A simple LIFO stack backed by std::vector.

◆ push()

template<typename T>
void containers::Stack< T >::push ( const T & value)
inline

Push a value onto the top of the stack.

Parameters
valueThe value to push.
Postcondition
size() is incremented by 1.

Definition at line 92 of file containers.hpp.

92 {
93 data_.push_back(value);
94 }

◆ size()

template<typename T>
std::size_t containers::Stack< T >::size ( ) const
inlinenodiscard

Get the number of elements.

Definition at line 123 of file containers.hpp.

123{ return data_.size(); }

◆ top()

template<typename T>
const T & containers::Stack< T >::top ( ) const
inlinenodiscard

Peek at the top element without removing it.

Returns
A const reference to the top element.
Exceptions
BufferUnderflowif the stack is empty.

Definition at line 114 of file containers.hpp.

114 {
115 if (data_.empty()) throw BufferUnderflow();
116 return data_.back();
117 }

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