[#bsl-stack-05]
= xref:bsl.adoc[bsl]::stack
:relfileprefix: ../
:mrdocs:

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

== Synopsis

Declared in `&lt;bslstl&lowbar;stack&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    class VALUE,
    class CONTAINER = xref:bsl/deque-0c.adoc[deque&lt;VALUE&gt;]&gt;
class stack;
----

== Description

Note that we never use `VALUE` in the implementation except in the default argument of `CONTAINER`&period; We use `CONTAINER&colon;&colon;value&lowbar;type` for everything, which means that if `CONTAINER` is specified, then `VALUE` is ignored&period;

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stack-05/const_reference.adoc[`const&lowbar;reference`] 
| This `typedef` is an alias for `const&lowbar;reference`&period;
| xref:bsl/stack-05/container_type.adoc[`container&lowbar;type`] 
| This `typedef` is an alias for `container&lowbar;type`&period;
| xref:bsl/stack-05/reference.adoc[`reference`] 
| This `typedef` is an alias for `reference`&period;
| xref:bsl/stack-05/size_type.adoc[`size&lowbar;type`] 
| This `typedef` is an alias for `size&lowbar;type`&period;
| xref:bsl/stack-05/value_type.adoc[`value&lowbar;type`] 
| This `typedef` is an alias to `CONTAINER&colon;&colon;value&lowbar;type`&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stack-05/2constructor-010.adoc[`stack`]         [.small]#[constructor]#
| Constructors
| xref:bsl/stack-05/operator_assign-0a.adoc[`operator&equals;`] 
| Assignment operators
| xref:bsl/stack-05/emplace.adoc[`emplace`] 
| Push onto this stack a newly created `value&lowbar;type` object constructed by forwarding `get&lowbar;allocator()` (if required) and the specified (variable number of) `args` to the corresponding constructor of `value&lowbar;type`&period; Return a reference providing modifiable access to the inserted element&period;
| xref:bsl/stack-05/empty.adoc[`empty`] 
| Return `true` if this stack contains no elements and `false` otherwise&period;
| xref:bsl/stack-05/pop.adoc[`pop`] 
| Remove the top element from this stack&period; The behavior is undefined if this stack is empty&period;
| xref:bsl/stack-05/push-08.adoc[`push`] 
| `push` overloads
| xref:bsl/stack-05/push_range.adoc[`push&lowbar;range`] 
| Push onto this stack the elements of the specified `range`&period; 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`&period;
| xref:bsl/stack-05/size.adoc[`size`] 
| Return the number of elements contained in this stack&period;
| xref:bsl/stack-05/swap.adoc[`swap`] 
| Exchange the value of this stack with the value of the specified `other` stack&period;
| xref:bsl/stack-05/top-06.adoc[`top`] 
| `top` overloads
| xref:bsl/stack-05/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;stack, UsesBslmaAllocator, BloombergLP&colon;&colon;bslma&colon;&colon;UsesBslmaAllocator&lt;container&lowbar;type&gt;&colon;&colon;value&gt;`] 
| Declare nested type traits for this type&period;
|===


== Protected Data Members

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stack-05/c.adoc[`c`] 
| The `c` data member&period;
|===


== Deduction Guides

[cols="1,4"]
|===
| Name| Description
| xref:bsl/stack-0f.adoc[`stack&lt;TYPE&gt;`] 
| Deduce the template parameter `VALUE` from the parameters supplied to the constructor of `stack`&period;
| xref:bsl/stack-06f.adoc[`stack&lt;TYPE, deque&lt;TYPE, ALLOCATOR&gt;&gt;`] 
| Deduce the template parameters `VALUE` and `CONTAINER` from the parameters supplied to the constructor of `stack`&period; This deduction guide does not participate unless the `ALLOCATOR` parameter meets the requirements for a standard allocator&period;
| xref:bsl/stack-06c.adoc[`stack&lt;t&lowbar;TYPE, deque&lt;t&lowbar;TYPE, t&lowbar;ALLOCATOR&gt;&gt;`] 
| Deduce the template parameters `VALUE` and `ALLOCATOR` from the parameters supplied to the constructor of `stack`&period; This deduction guide does not participate unless the `t&lowbar;ALLOCATOR` parameter meets the requirements for a standard allocator&period;
| xref:bsl/stack-0c.adoc[`stack&lt;CONTAINER::value&lowbar;type, CONTAINER&gt;`] 
| Deduce the template parameters `VALUE` and `CONTAINER` from the parameters supplied to the constructor of `stack`&period; This deduction guide does not participate if the parameter meets the requirements for a standard allocator&period;
| xref:bsl/stack-06b.adoc[`stack&lt;CONTAINER::value&lowbar;type, CONTAINER&gt;`] 
| Deduce the template parameters `VALUE` and `CONTAINER` from the parameters supplied to the constructor of `stack`&period; This deduction guide does not participate unless the supplied allocator is convertible to the underlying container&apos;s `allocator&lowbar;type`&period;
| xref:bsl/stack-01.adoc[`stack&lt;ranges::range&lowbar;value&lowbar;t&lt;t&lowbar;RANGE&gt;&gt;`] 
| Deduce the template parameter `VALUE` from the parameters supplied to the constructor of `stack`&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:bsl/operator_3way-03e.adoc[bsl::operator&lt;&equals;&gt;]`
| Same as the related overload above for `operator&lt;&equals;&gt;`&period;
| `xref:bsl/operator_ge-0f.adoc[bsl::operator&gt;&equals;]`
| Same as the related overload above for `operator&gt;&equals;`&period;
| `xref:bsl/operator_le-0b.adoc[bsl::operator&lt;&equals;]`
| Return whether the specified stacks compare lexicographically&semi; see the non&hyphen;member `operator&lt;&equals;` in the `bsl` namespace&period;
| `xref:bsl/operator_gt-017.adoc[bsl::operator&gt;]`
| Return whether the specified stacks compare lexicographically&semi; see the non&hyphen;member `operator&gt;` in the `bsl` namespace&period;
| `xref:bsl/operator_lt-08.adoc[bsl::operator&lt;]`
| Return whether the specified stacks compare lexicographically&semi; see the non&hyphen;member `operator&lt;` in the `bsl` namespace&period;
| `xref:bsl/operator_not_eq-03.adoc[bsl::operator!&equals;]`
| Same as the related overload above for `operator!&equals;`&period;
| `xref:bsl/operator_eq-00.adoc[bsl::operator&equals;&equals;]`
| Same as the related overload above for `operator&equals;&equals;`&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:bsl/operator_not_eq-079.adoc[`operator!&equals;`]
| Return `true` if the specified `lhs` and `rhs` objects do not have the same value, and `false` otherwise&period; Two `stack` objects `lhs` and `rhs` do not have the same value if they do not have the same number of elements, or some element in the ordered sequence of elements of `lhs` does not have the same value as the corresponding element in the ordered sequence of elements of `rhs`&period; This method requires that the (template parameter) type `VALUE` be `equality&hyphen;comparable` (see &lcub;Requirements on `VALUE`&rcub;)&period;
| xref:bsl/operator_lt-0c.adoc[`operator&lt;`]
| Return `true` if the value of the specified `lhs` stack is lexicographically less than that of the specified `rhs` stack, and `false` otherwise&period; Given iterators `i` and `j` over the respective sequences `&lsqb;lhs&period;begin() &period;&period; lhs&period;end())&rsqb;` and `&lsqb;rhs&period;begin() &period;&period; rhs&period;end())&rsqb;`, the value of stack `lhs` is lexicographically less than that of stack `rhs` if `true &equals;&equals; &ast;i &lt; &ast;j` for the first pair of corresponding iterator positions where `&ast;i &lt; &ast;j` and `&ast;j &lt; &ast;i` are not both `false`&period; If no such corresponding iterator position exists, the value of `lhs` is lexicographically less than that of `rhs` if `lhs&period;size() &lt; rhs&period;size()`&period; This method requires that `operator&lt;`, inducing a total order, be defined for `value&lowbar;type`&period;
| xref:bsl/operator_le-0ec.adoc[`operator&lt;&equals;`]
| Return `true` if the value of the specified `lhs` stack is lexicographically less than or equal to that of the specified `rhs` stack, and `false` otherwise&period; The value of stack `lhs` is lexicographically less than or equal to that of stack `rhs` if `rhs` is not lexicographically less than `lhs` (see `operator&lt;`)&period; This method requires that `operator&lt;`, inducing a total order, be defined for `value&lowbar;type`&period; Note that this operator returns `!(rhs &lt; lhs)`&period;
| xref:bsl/operator_3way-01d.adoc[`operator&lt;&equals;&gt;`]
| Same as the related overload above for `operator&lt;&equals;&gt;`&period;
| xref:bsl/operator_eq-0e3.adoc[`operator&equals;&equals;`]
| Return `true` if the specified `lhs` and `rhs` objects have the same value, and `false` otherwise&period; Two `stack` objects `lhs` and `rhs` have the same value if they have the same number of elements, and each element in the ordered sequence of elements of `lhs` has the same value as the corresponding element in the ordered sequence of elements of `rhs`&period; This method requires that the (template parameter) type `VALUE` be `equality&hyphen;comparable` (see &lcub;Requirements on `VALUE`&rcub;)&period;
| xref:bsl/operator_gt-00.adoc[`operator&gt;`]
| Return `true` if the value of the specified `lhs` stack is lexicographically greater than that of the specified `rhs` stack, and `false` otherwise&period; The value of stack `lhs` is lexicographically greater than that of stack `rhs` if `rhs` is lexicographically less than `lhs` (see `operator&lt;`)&period; This method requires that `operator&lt;`, inducing a total order, be defined for `value&lowbar;type`&period; Note that this operator returns `rhs &lt; lhs`&period;
| xref:bsl/operator_ge-0b.adoc[`operator&gt;&equals;`]
| Return `true` if the value of the specified `lhs` stack is lexicographically greater than or equal to that of the specified `rhs` stack, and `false` otherwise&period; The value of stack `lhs` is lexicographically greater than or equal to that of stack `rhs` if `lhs` is not lexicographically less than `rhs` (see `operator&lt;`)&period; This method requires that `operator&lt;`, inducing a total order, be defined for `value&lowbar;type`&period; Note that this operator returns `!(lhs &lt; rhs)`&period;
| xref:bsl/swap-0cb.adoc[`swap`]
| Swap the value of the specified `lhs` stack with the value of the specified `rhs` stack&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
