BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsl::stack< VALUE, CONTAINER > Class Template Reference

#include <bslstl_stack.h>

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
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

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)
 
template<class INPUT_ITER >
 stack (INPUT_ITER first, INPUT_ITER last)
 
template<class INPUT_ITER , class ALLOCATOR >
 stack (INPUT_ITER first, INPUT_ITER last, const ALLOCATOR &allocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
 
template<class t_RANGE >
 stack (from_range_t, BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
 
template<class t_RANGE , class t_ALLOCATOR >
 stack (from_range_t, BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range, const t_ALLOCATOR &allocator, typename enable_if< bsl::uses_allocator< CONTAINER, t_ALLOCATOR >::value, t_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)
 
void push (BloombergLP::bslmf::MovableRef< value_type > value)
 
template<class t_RANGE >
void push_range (BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
 
bool empty () const
 
size_type size () const
 
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 > &)
 

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/14]

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/14]

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/14]

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/14]

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/14]

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/14]

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/14]

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/14]

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/14]

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/14]

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
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.

◆ stack() [11/14]

template<class VALUE , class CONTAINER >
template<class INPUT_ITER >
bsl::stack< VALUE, CONTAINER >::stack ( INPUT_ITER  first,
INPUT_ITER  last 
)
inline

Create a stack passing the specified first and last to the constructor of the underlying container. Optionally specify an allocator used to supply memory. If allocator is not specified, a default-constructed object of the (template parameter) type ALLOCATOR is used.

◆ stack() [12/14]

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

◆ stack() [13/14]

template<class VALUE , class CONTAINER >
template<class t_RANGE >
bsl::stack< VALUE, CONTAINER >::stack ( from_range_t  ,
BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE)  range 
)
inline

Create a stack from the elements of the specifed range. Optionally specify an allocator used to supply memory. If allocator is not specified, a default-constructed object of the (template parameter) type t_ALLOCATOR is used.

Note
Note that range must meet the requirements of an input range and the values from range must have a type matching or convertible to (template parameter) VALUE.

◆ stack() [14/14]

template<class VALUE , class CONTAINER >
template<class t_RANGE , class t_ALLOCATOR >
bsl::stack< VALUE, CONTAINER >::stack ( from_range_t  ,
BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE)  range,
const t_ALLOCATOR &  allocator,
typename enable_if< bsl::uses_allocator< CONTAINER, t_ALLOCATOR >::value, t_ALLOCATOR >::type *  = 0 
)
inline

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.

Precondition
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

Push the specified value onto the top of this stack.

◆ push_range()

template<class VALUE , class CONTAINER >
template<class t_RANGE >
void bsl::stack< VALUE, CONTAINER >::push_range ( BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE)  range)

Push onto this stack the elements of the specified range.

Note
Note that range must meet the requirements of an input range and the values from range must have a type matching or convertible to (template parameter) VALUE.

◆ size()

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

Return the number of elements contained in this stack.

◆ 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.

Precondition
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.

Precondition
The behavior is undefined if this stack is empty.

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