deduction guides for std::stack

< cpp‎ | container‎ | stack

Defined in header <stack>
template<class Container>


  -> stack<typename Container::value_type, Container>;
(1) (since C++17)
template<class Container, class Allocator>

stack(Container, Allocator)

  -> stack<typename Container::value_type, Container>;
(2) (since C++17)

These deduction guides are provided for stack to allow deduction from underlying container type. This overload only participates in overload resolution if Alloc satisfies Allocator, and Container does not satisfy Allocator and, for overload (2), if std::uses_allocator_v<Container, Allocator> is true

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.


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