BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::stack< VALUE, CONTAINER > Class Template Reference

#include <bslstl_stack.h>

Public Types

typedef CONTAINER::value_type value_type
 
typedef CONTAINER::reference reference
 
typedef CONTAINER::const_reference const_reference
 
typedef CONTAINER::size_type size_type
 
typedef CONTAINER container_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION_IF (stack, BloombergLP::bslma::UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator< container_type >::value)
 
 stack ()
 
 stack (const stack &original)
 
 stack (BloombergLP::bslmf::MovableRef< stack > original)
 
 stack (const CONTAINER &container)
 
 stack (BloombergLP::bslmf::MovableRef< CONTAINER > container)
 
template<class ALLOCATOR >
 stack (const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
template<class ALLOCATOR >
 stack (const CONTAINER &container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
template<class ALLOCATOR >
 stack (const stack &original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
template<class ALLOCATOR >
 stack (BloombergLP::bslmf::MovableRef< CONTAINER > container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
template<class ALLOCATOR >
 stack (BloombergLP::bslmf::MovableRef< stack > original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
stackoperator= (const stack &rhs)
 
stackoperator= (BloombergLP::bslmf::MovableRef< stack > rhs) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(false)
 
template<class... Args>
reference emplace (Args &&... args)
 
void pop ()
 
void push (const value_type &value)
 Push the specified value onto the top of this stack.
 
void push (BloombergLP::bslmf::MovableRef< value_type > value)
 
bool empty () const
 
size_type size () const
 Return the number of elements contained in this stack.
 
const_reference top () const
 

Public Attributes

void swap(stack &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl reference top ()
 

Protected Attributes

container_type c
 

Friends

template<class VAL , class CONT >
bool operator== (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 
template<class VAL , class CONT >
bool operator!= (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 
template<class VAL , class CONT >
bool operator< (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 
template<class VAL , class CONT >
bool operator> (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 
template<class VAL , class CONT >
bool operator<= (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 
template<class VAL , class CONT >
bool operator>= (const stack< VAL, CONT > &, const stack< VAL, CONT > &)
 

Detailed Description

template<class VALUE, class CONTAINER = deque<VALUE>>
class bsl::stack< VALUE, CONTAINER >

This class defines a container adapter which supports access primarily via push, pop, and top. This type can be based on a variety of other container types, including deque, vector, and list. This type is value-semantic if the supporting CONTAINER and VALUE are value-semantic.

Note that we never use VALUE in the implementation except in the default argument of CONTAINER. We use CONTAINER::value_type for everything, which means that if CONTAINER is specified, then VALUE is ignored.

See bslstl_stack

Member Typedef Documentation

◆ const_reference

template<class VALUE , class CONTAINER = deque<VALUE>>
typedef CONTAINER::const_reference bsl::stack< VALUE, CONTAINER >::const_reference

◆ container_type

template<class VALUE , class CONTAINER = deque<VALUE>>
typedef CONTAINER bsl::stack< VALUE, CONTAINER >::container_type

◆ reference

template<class VALUE , class CONTAINER = deque<VALUE>>
typedef CONTAINER::reference bsl::stack< VALUE, CONTAINER >::reference

◆ size_type

template<class VALUE , class CONTAINER = deque<VALUE>>
typedef CONTAINER::size_type bsl::stack< VALUE, CONTAINER >::size_type

◆ value_type

template<class VALUE , class CONTAINER = deque<VALUE>>
typedef CONTAINER::value_type bsl::stack< VALUE, CONTAINER >::value_type

Constructor & Destructor Documentation

◆ stack() [1/10]

template<class VALUE , class CONTAINER >
bsl::stack< VALUE, CONTAINER >::stack ( )
inlineexplicit

Create an empty stack. No allocator will be provided to the underlying container. That container's memory allocation will be provided by the default allocator of its type.

◆ stack() [2/10]

template<class VALUE , class CONTAINER >
bsl::stack< VALUE, CONTAINER >::stack ( const stack< VALUE, CONTAINER > &  original)
inline

Create a stack having the value of the specified original. The currently installed default allocator is used to supply memory.

◆ stack() [3/10]

template<class VALUE , class CONTAINER >
bsl::stack< VALUE, CONTAINER >::stack ( BloombergLP::bslmf::MovableRef< stack< VALUE, CONTAINER > >  original)
inline

Create a stack having the value of the specified original by moving the contents of original to the new stack. The allocator associated with original is propagated for use in the new stack. original is left in a valid but unspecified state.

◆ stack() [4/10]

template<class VALUE , class CONTAINER >
bsl::stack< VALUE, CONTAINER >::stack ( const CONTAINER &  container)
inlineexplicit

Create a stack whose underlying container has the value of the specified container. The currently installed default allocator is used to supply memory.

◆ stack() [5/10]

template<class VALUE , class CONTAINER >
bsl::stack< VALUE, CONTAINER >::stack ( BloombergLP::bslmf::MovableRef< CONTAINER >  container)
inlineexplicit

Create a stack whose underlying container has the value of the specified container (on entry) by moving the contents of container to the new stack. The allocator associated with container is propagated for use in the new stack. container is left in a valid but unspecified state.

◆ stack() [6/10]

template<class VALUE , class CONTAINER >
template<class ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( const ALLOCATOR &  basicAllocator,
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *  = 0 
)
inlineexplicit

Create an empty stack, and use the specified basicAllocator to supply memory. If CONTAINER::allocator_type does not exist, this constructor may not be used.

◆ stack() [7/10]

template<class VALUE , class CONTAINER >
template<class ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( const CONTAINER &  container,
const ALLOCATOR &  basicAllocator,
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *  = 0 
)
inline

Create a stack whose underlying container has the value of the specified container, and use the specified basicAllocator to supply memory. If CONTAINER::allocator_type does not exist, this constructor may not be used.

◆ stack() [8/10]

template<class VALUE , class CONTAINER >
template<class ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( const stack< VALUE, CONTAINER > &  original,
const ALLOCATOR &  basicAllocator,
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *  = 0 
)
inline

Create a stack having the value of the specified stack original and use the specified basicAllocator to supply memory. If CONTAINER::allocator_type does not exist, this constructor may not be used.

◆ stack() [9/10]

template<class VALUE , class CONTAINER >
template<class ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( BloombergLP::bslmf::MovableRef< CONTAINER >  container,
const ALLOCATOR &  basicAllocator,
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *  = 0 
)
inline

Create a stack whose underlying container has the value of the specified container (on entry) that uses basicAllocator to supply memory by using the allocator-extended move constructor of CONTAINER.container' is left in a valid but unspecified state. A bslma::Allocator * can be supplied for basicAllocator if the (template parameter) ALLOCATOR is bsl::allocator (the default). This method assumes that CONTAINER has a move constructor. If CONTAINER::allocator_type does not exist, this constructor may not be used.

◆ stack() [10/10]

template<class VALUE , class CONTAINER >
template<class ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( BloombergLP::bslmf::MovableRef< stack< VALUE, CONTAINER > >  original,
const ALLOCATOR &  basicAllocator,
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *  = 0 
)
inline

Create a stack having the value of the specified original (on entry) that uses basicAllocator to supply memory by using the allocator-extended moved constructor of CONTAINER. original is left in a valid but unspecified state. Note that a bslma::Allocator * can be supplied for basicAllocator if the (template parameter) ALLOCATOR is bsl::allocator (the default). Also note that this method assumes that CONTAINER has a move constructor. Also note that if CONTAINER::allocator_type does not exist, this constructor may not be used.

Member Function Documentation

◆ BSLMF_NESTED_TRAIT_DECLARATION_IF()

template<class VALUE , class CONTAINER = deque<VALUE>>
bsl::stack< VALUE, CONTAINER >::BSLMF_NESTED_TRAIT_DECLARATION_IF ( stack< VALUE, CONTAINER >  ,
BloombergLP::bslma::UsesBslmaAllocator  ,
BloombergLP::bslma::UsesBslmaAllocator< container_type >::value   
)

◆ emplace()

template<class VALUE , class CONTAINER >
template<class... Args>
stack< VALUE, CONTAINER >::reference bsl::stack< VALUE, CONTAINER >::emplace ( Args &&...  args)
inline

Push onto this stack a newly created value_type object constructed by forwarding get_allocator() (if required) and the specified (variable number of) args to the corresponding constructor of value_type. Return a reference providing modifiable access to the inserted element.

◆ empty()

template<class VALUE , class CONTAINER >
bool bsl::stack< VALUE, CONTAINER >::empty ( ) const
inline

Return true if this stack contains no elements and false otherwise.

◆ operator=() [1/2]

template<class VALUE , class CONTAINER >
stack< VALUE, CONTAINER > & bsl::stack< VALUE, CONTAINER >::operator= ( BloombergLP::bslmf::MovableRef< stack< VALUE, CONTAINER > >  rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved to this stack using the move-assignment operator of CONTAINER. rhs is left in a valid but unspecified state, and if an exception is thrown, *this is left in a valid but unspecified state.

◆ operator=() [2/2]

template<class VALUE , class CONTAINER >
stack< VALUE, CONTAINER > & bsl::stack< VALUE, CONTAINER >::operator= ( const stack< VALUE, CONTAINER > &  rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object.

◆ pop()

template<class VALUE , class CONTAINER >
void bsl::stack< VALUE, CONTAINER >::pop ( )
inline

Remove the top element from this stack. The behavior is undefined if this stack is empty.

◆ push() [1/2]

template<class VALUE , class CONTAINER >
void bsl::stack< VALUE, CONTAINER >::push ( BloombergLP::bslmf::MovableRef< value_type value)
inline

Push onto this stack a value_type object having the value of the specified value (on entry) by moving the contents of value to the new object on this stack. value is left in a valid but unspecified state.

◆ push() [2/2]

template<class VALUE , class CONTAINER >
void bsl::stack< VALUE, CONTAINER >::push ( const value_type value)
inline

◆ size()

template<class VALUE , class CONTAINER >
CONTAINER::size_type bsl::stack< VALUE, CONTAINER >::size ( ) const
inline

◆ top()

template<class VALUE , class CONTAINER = deque<VALUE>>
const_reference bsl::stack< VALUE, CONTAINER >::top ( ) const

Return a reference providing non-modifiable access to the element at the top of this stack. The behavior is undefined if the stack is empty.

Friends And Related Symbol Documentation

◆ operator!=

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator!= ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

◆ operator<

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator< ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

◆ operator<=

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator<= ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

◆ operator==

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator== ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

◆ operator>

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator> ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

◆ operator>=

template<class VALUE , class CONTAINER = deque<VALUE>>
template<class VAL , class CONT >
bool operator>= ( const stack< VAL, CONT > &  ,
const stack< VAL, CONT > &   
)
friend

Member Data Documentation

◆ c

template<class VALUE , class CONTAINER = deque<VALUE>>
container_type bsl::stack< VALUE, CONTAINER >::c
protected

◆ top

template<class VALUE , class CONTAINER >
CONTAINER::const_reference bsl::stack< VALUE, CONTAINER >::top
inline

Exchange the value of this stack with the value of the specified other stack. Return a reference to the element at the top of this stack. The behavior is undefined if this stack is empty.


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