DSC Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
DSC::Stack< T > Class Template Reference

Public Member Functions

 Stack (Stack< T > &&stack)
 
Stack< T > & operator= (Stack< T > &&stack)
 
void clear ()
 Clears the stack.
 
bool is_empty () const
 Checks if the stack is empty. More...
 
void push (const T &value)
 Adds an element at the top of the stack. More...
 
pop ()
 Removes the element at the top of the stack. More...
 

Static Public Member Functions

static Stack< T > from_range (const T &a, const T &b, const T &step)
 Creates a stack from all elements ranging between certain values. More...
 

Member Function Documentation

◆ from_range()

template<typename T >
DSC::Stack< T > DSC::Stack< T >::from_range ( const T &  a,
const T &  b,
const T &  step 
)
static

Creates a stack from all elements ranging between certain values.

Parameters
[in]astart of the count
[in]bcount limit
[in]stepcount step
Returns
A stack containing a, a+step, ..., up to b, not including b

This method is only available with aritmetic types: Stack<int>::from_range(). For example, Stack<Pizza>::from_range() raises a syntax error.

A type is considered arithmetic if it allows for addition (+), substraction (-), comparison ( <, >) and has a "zero" element (x+0=x, x-0=x).

Extra care is needed when choosing the step

Stack<int> s1 = Stack<int>::from_range(1, 10, 2); // ok: 1,3,5,7,9
Stack<int> s2 = Stack<int>::from_range(10, 1, -3); // ok: 10,7,4
Stack<int> s2 = Stack<int>::from_range(5, 1, 1); // out of range!
Stack<int> s2 = Stack<int>::from_range(1, 5, -1); // out of range!
Definition: stack.hpp:13
static Stack< T > from_range(const T &a, const T &b, const T &step)
Creates a stack from all elements ranging between certain values.
Definition: stack.hpp:137

◆ is_empty()

template<typename T >
bool DSC::Stack< T >::is_empty

Checks if the stack is empty.

Returns
true is stack contains no elements, false otherwise

◆ pop()

template<typename T >
T DSC::Stack< T >::pop

Removes the element at the top of the stack.

Returns
The popped element

◆ push()

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

Adds an element at the top of the stack.

Parameters
[in]valueElement to be added

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