Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::AutoStack< ValueType > Class Template Reference

A stack whose elements are automatic variables. More...

#include <bond/stl/autostack.h>

Classes

class  Element
 A single value on an AutoStack, owned by the scope that pushed it. More...
class  Iterator
 An iterator that visits the values of an AutoStack from the top to the bottom. More...
class  ConstIterator
 An iterator that visits the values of a const AutoStack from the top to the bottom. More...

Public Member Functions

 AutoStack () noexcept
 Constructs an empty AutoStack.
 ~AutoStack ()
 Destroys the AutoStack. All Elements must have been destroyed beforehand.
 AutoStack (const AutoStack &other)=delete
AutoStack & operator= (const AutoStack &other)=delete
template<typename... Args>
Element Push (Args &&... args)
 Pushes a value onto the top of the stack.
ValueType & GetTop ()
 Returns a reference to the value at the top of the stack. The stack must not be empty.
const ValueType & GetTop () const
 Returns a const reference to the value at the top of the stack. The stack must not be empty.
void SetTop (const ValueType &value)
 Assigns a copy of the given value to the value at the top of the stack. The stack must not be empty.
void SetTop (ValueType &&value)
 Moves the given value into the value at the top of the stack. The stack must not be empty.
bool IsEmpty () const noexcept
 Returns whether the stack contains no values.
bool Contains (const ValueType &value) const
 Returns whether any value on the stack compares equal to the given value.
Iterator begin () noexcept
 Returns an Iterator referring to the value at the top of the stack.
ConstIterator begin () const noexcept
 Returns a ConstIterator referring to the value at the top of the stack.
ConstIterator cbegin () const noexcept
 Returns a ConstIterator referring to the value at the top of the stack.
Iterator end () noexcept
 Returns an Iterator referring to the position past the value at the bottom of the stack.
ConstIterator end () const noexcept
 Returns a ConstIterator referring to the position past the value at the bottom of the stack.
ConstIterator cend () const noexcept
 Returns a ConstIterator referring to the position past the value at the bottom of the stack.

Detailed Description

template<typename ValueType>
class Bond::AutoStack< ValueType >

A stack whose elements are automatic variables.

Pushing a value onto the stack returns an Element that must be kept alive for as long as the value should remain on the stack; destroying the Element pops the value. Elements must be destroyed in reverse order of creation and must not outlive the stack. The stack cannot be copied or moved.

Template Parameters
ValueTypeThe type of the values held by the stack.

Constructor & Destructor Documentation

◆ AutoStack() [1/2]

template<typename ValueType>
Bond::AutoStack< ValueType >::AutoStack ( )
inlinenoexcept

Constructs an empty AutoStack.

◆ ~AutoStack()

template<typename ValueType>
Bond::AutoStack< ValueType >::~AutoStack ( )
inline

Destroys the AutoStack. All Elements must have been destroyed beforehand.

◆ AutoStack() [2/2]

template<typename ValueType>
Bond::AutoStack< ValueType >::AutoStack ( const AutoStack< ValueType > & other)
delete

Member Function Documentation

◆ begin() [1/2]

template<typename ValueType>
ConstIterator Bond::AutoStack< ValueType >::begin ( ) const
inlinenoexcept

Returns a ConstIterator referring to the value at the top of the stack.

◆ begin() [2/2]

template<typename ValueType>
Iterator Bond::AutoStack< ValueType >::begin ( )
inlinenoexcept

Returns an Iterator referring to the value at the top of the stack.

◆ cbegin()

template<typename ValueType>
ConstIterator Bond::AutoStack< ValueType >::cbegin ( ) const
inlinenoexcept

Returns a ConstIterator referring to the value at the top of the stack.

◆ cend()

template<typename ValueType>
ConstIterator Bond::AutoStack< ValueType >::cend ( ) const
inlinenoexcept

Returns a ConstIterator referring to the position past the value at the bottom of the stack.

◆ Contains()

template<typename ValueType>
bool Bond::AutoStack< ValueType >::Contains ( const ValueType & value) const
inline

Returns whether any value on the stack compares equal to the given value.

Parameters
valueThe value to search for.

◆ end() [1/2]

template<typename ValueType>
ConstIterator Bond::AutoStack< ValueType >::end ( ) const
inlinenoexcept

Returns a ConstIterator referring to the position past the value at the bottom of the stack.

◆ end() [2/2]

template<typename ValueType>
Iterator Bond::AutoStack< ValueType >::end ( )
inlinenoexcept

Returns an Iterator referring to the position past the value at the bottom of the stack.

◆ GetTop() [1/2]

template<typename ValueType>
ValueType & Bond::AutoStack< ValueType >::GetTop ( )
inline

Returns a reference to the value at the top of the stack. The stack must not be empty.

◆ GetTop() [2/2]

template<typename ValueType>
const ValueType & Bond::AutoStack< ValueType >::GetTop ( ) const
inline

Returns a const reference to the value at the top of the stack. The stack must not be empty.

◆ IsEmpty()

template<typename ValueType>
bool Bond::AutoStack< ValueType >::IsEmpty ( ) const
inlinenoexcept

Returns whether the stack contains no values.

◆ operator=()

template<typename ValueType>
AutoStack & Bond::AutoStack< ValueType >::operator= ( const AutoStack< ValueType > & other)
delete

◆ Push()

template<typename ValueType>
template<typename... Args>
Element Bond::AutoStack< ValueType >::Push ( Args &&... args)
inlinenodiscard

Pushes a value onto the top of the stack.

Parameters
argsThe arguments forwarded to the constructor of the value.
Returns
An Element that keeps the value on the stack for as long as it is alive. Discarding the result destroys the Element immediately, which pops the value again.

◆ SetTop() [1/2]

template<typename ValueType>
void Bond::AutoStack< ValueType >::SetTop ( const ValueType & value)
inline

Assigns a copy of the given value to the value at the top of the stack. The stack must not be empty.

Parameters
valueThe value to be copied.

◆ SetTop() [2/2]

template<typename ValueType>
void Bond::AutoStack< ValueType >::SetTop ( ValueType && value)
inline

Moves the given value into the value at the top of the stack. The stack must not be empty.

Parameters
valueThe value to be moved.

The documentation for this class was generated from the following file:
  • include/bond/stl/autostack.h