Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/stack"

From cppreference.com
< cpp‎ | containerRedirect page
m (fmt: rm extra \n before #Member types section)
m (Redirected page to enwiki:Rust (programming language))
Line 1: Line 1:
{{cpp/title|stack}}
+
#REDIRECT [[enwiki:Rust_(programming_language)]]
{{cpp/container/stack/navbar}}
+
{{ddcl|header=stack|1=
+
template<
+
    class T,
+
    class Container = std::deque<T>
+
> class stack;
+
}}
+
 
+
The {{tt|std::stack}} class is a container adaptor that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure.
+
 
+
The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.
+
 
+
===Template parameters===
+
{{par begin}}
+
{{par|T|The type of the stored elements. The behavior is undefined if {{tt|T}} is not the same type as {{tt|Container::value_type}}.<!-- LWG2566 -->}}
+
{{par|Container|The type of the underlying container to use to store the elements. The container must satisfy the requirements of {{named req|SequenceContainer}}. Additionally, it must provide the following functions with the usual semantics:
+
* {{tt|back()}}
+
* {{tt|push_back()}}
+
* {{tt|pop_back()}}
+
 
+
The standard containers {{lc|std::vector}} (including {{ltt|cpp/container/vector_bool|std::vector<bool>}}), {{lc|std::deque}} and {{lc|std::list}} satisfy these requirements.  By default, if no container class is specified for a particular stack class instantiation, the standard container {{lc|std::deque}} is used.
+
}}{{par end}}
+
 
+
===Member types===
+
{{dsc begin}}
+
{{dsc hitem|Member type|Definition}}
+
{{dsc inc|cpp/container/dsc container_type|stack}}
+
{{dsc inc|cpp/container/dsc value_type|stack}}
+
{{dsc inc|cpp/container/dsc size_type|stack}}
+
{{dsc inc|cpp/container/dsc reference|stack}}
+
{{dsc inc|cpp/container/dsc const_reference|stack}}
+
{{dsc end}}
+
 
+
===Member functions===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc constructor|stack}}
+
{{dsc inc|cpp/container/dsc destructor|stack}}
+
{{dsc inc|cpp/container/dsc operator{{=}}|stack}}
+
 
+
{{dsc h2|Element access}}
+
{{dsc inc|cpp/container/dsc top|stack}}
+
 
+
{{dsc h2|Capacity}}
+
{{dsc inc|cpp/container/dsc empty|stack}}
+
{{dsc inc|cpp/container/dsc size|stack}}
+
 
+
{{dsc h2|Modifiers}}
+
{{dsc inc|cpp/container/dsc push|stack}}
+
{{dsc inc|cpp/container/dsc emplace|stack}}
+
{{dsc inc|cpp/container/dsc push_range|stack}}
+
{{dsc inc|cpp/container/dsc pop|stack}}
+
{{dsc inc|cpp/container/dsc swap|stack}}
+
 
+
{{dsc h1|Member objects}}
+
{{dsc inc|cpp/container/dsc c|stack}}
+
{{dsc end}}
+
 
+
===Non-member functions===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc operator_cmp|stack}}
+
{{dsc inc|cpp/container/dsc swap2|stack}}
+
{{dsc end}}
+
 
+
===Helper classes===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc uses_allocator|stack}}
+
{{dsc end}}
+
 
+
{{rrev|noborder=true|since=c++17|{{=}}{{=}}{{=}}{{rl|deduction guides|Deduction guides}}{{=}}{{=}}{{=}}}}
+
 
+
===Notes===
+
{{ftm begin|std=1|comment=1}}
+
{{ftm|__cpp_lib_containers_ranges|value=202202L|std=C++23|Ranges construction and insertion for containers}}
+
{{ftm end}}
+
 
+
===Example===
+
{{example
+
|Comment
+
|code=
+
|output=
+
}}
+
 
+
===Defect reports===
+
{{dr list begin}}
+
{{dr list item|wg=lwg|dr=307|std=C++98|before={{tt|Container}} could not be {{tt|std::vector<bool>}}|after=allowed}}
+
{{dr list end}}
+
 
+
===See also===
+
{{dsc begin}}
+
{{dsc inc|cpp/container/dsc vector}}
+
{{dsc inc|cpp/container/dsc vector bool}}
+
{{dsc inc|cpp/container/dsc deque}}
+
{{dsc inc|cpp/container/dsc list}}
+
{{dsc end}}
+
 
+
{{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|tr|zh}}
+

Revision as of 12:48, 30 July 2023