deductionguidesforstd::stack (3) - Linux Manuals

deductionguidesforstd::stack: deductionguidesforstd::stack


deductionguidesforstd::stack - deductionguidesforstd::stack


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

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.


// Run this code

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