deduction guides for std::stack
Defined in header <stack> |
||
---|---|---|
template< class Container > stack( Container ) -> stack<typename Container::value_type, Container>; |
(1) | (since C++17) |
template< class InputIt > stack( InputIt, InputIt ) -> stack<typename std::iterator_traits<InputIt>::value_type>; |
(2) | (since C++23) |
template< class Container, class Alloc > stack( Container, Alloc ) -> stack<typename Container::value_type, Container>; |
(3) | (since C++17) |
template< class InputIt, class Alloc > stack( InputIt, InputIt, Alloc ) -> stack<typename std::iterator_traits<InputIt>::value_type, std::deque<typename std::iterator_traits<InputIt>::value_type, Alloc>>; |
(4) | (since C++23) |
These deduction guides are provided for stack
to allow deduction from underlying container type.
std::deque<typename std::iterator_traits<InputIt>::value_type>
as the underlying container type.
These overloads participate in overload resolution only if.
-
InputIt
(if exists) satisfies LegacyInputIterator, -
Container
(if exists) does not satisfy Allocator, - for (3) (until C++23)(4) (since C++23),
Alloc
satisfies Allocator, and -
std::uses_allocator_v<Container, Alloc>
istrue
if bothContainer
andAlloc
exist.
Note: the extent to which the library determines that a type does not satisfy LegacyInputIterator 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 satisfy Allocator is unspecified, except that as a minimum the member type Alloc::value_type
must exist and the expression std::declval<Alloc&>().allocate(std::size_t{})
must be well-formed when treated as an unevaluated operand.
Example
#include <vector> #include <stack> int main() { std::vector<int> v = {1,2,3,4}; std::stack s{v}; // guide #1 deduces std::stack<int, vector<int>> }
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/stack/deduction_guides