std::stack
(C++17) | ||||
Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
Associative | ||||
Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Views | ||||
(C++20) | ||||
(C++23) | ||||
Tables | ||||
Iterator invalidation | ||||
Member function table | ||||
Non-member function table |
std::stack
Member functions | ||||
Element access | ||||
Capacity | ||||
Modifiers | ||||
(C++23) | ||||
(C++11) | ||||
(C++11) | ||||
Non-member functions | ||||
(C++11) | ||||
Helper classes | ||||
(C++11) | ||||
(C++23) | ||||
Deduction guides(C++17) |
Defined in header <stack> | ||
template<class Container> stack( Container) | (1) | (since C++17) |
template<class Container,class Alloc> stack( Container, Alloc) | (2) | (since C++17) |
template<class InputIt> stack( InputIt, InputIt) | (3) | (since C++23) |
template<class InputIt,class Alloc> stack( InputIt, InputIt, Alloc) | (4) | (since C++23) |
template<ranges::input_range R> stack(std::from_range_t, R&&) | (5) | (since C++23) |
template<ranges::input_range R,class Allocator> stack(std::from_range_t, R&&, Allocator) | (6) | (since C++23) |
Thesededuction guides are provided forstack
to allow deduction from underlying container type.
These overloads participate in overload resolution only if
InputIt
(if exists) satisfiesLegacyInputIterator,Container
(if exists) does not satisfyAllocator,Alloc
satisfiesAllocator, andContainer
andAlloc
exist.Note: the extent to which the library determines that a type does not satisfyLegacyInputIterator is unspecified, except that as a minimum integral types do not qualify as input iterators. Likewise, the extent to which it determines that a type does not satisfyAllocator is unspecified, except that as a minimum the member typeAlloc::value_type
must exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as an unevaluated operand.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_adaptor_iterator_pair_constructor | 202106L | (C++23) | Iterator pair constructors forstd::queue andstd::stack; overloads(2) and(4) |
__cpp_lib_containers_ranges | 202202L | (C++23) | Ranges-aware construction and insertion; overloads(5) and(6) |
#include <stack>#include <vector> int main(){std::vector<int> v={1,2,3,4};std::stack s{v};// guide #1 deduces std::stack<int, vector<int>>}