Namespaces
Variants
Views
Actions

deduction guides for std::queue

From cppreference.com
< cpp‎ | container‎ | queue
Defined in header <queue>
template<class Container>

queue(Container)

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

queue(InputIt, InputIt)

  -> queue</*iter-value-t*/<InputIt>>;
(2) (since C++23)
template<class Container, class Alloc>

queue(Container, Alloc)

  -> queue<typename Container::value_type, Container>;
(3) (since C++17)
template<class InputIt, class Alloc>

queue(InputIt, InputIt, Alloc)
  -> queue</*iter-value-t*/<InputIt>,

    std::deque</*iter-value-t*/<InputIt>, Alloc>>;
(4) (since C++23)

These deduction guides are provided for queue to allow deduction from underlying container type.

1) Deduces underlying container type from the argument.
2) Deduces the element type from the iterator, using std::deque</*iter-value-t*/<InputIt>> as the underlying container type, where /*iter-value-t*/<InputIt> denotes typename std::iterator_traits<InputIt>::value_type.
3-4) Same as (1-2), except that the allocator is provided.

These overloads participate in overload resolution only if

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.

[edit] Example

#include <vector>
#include <queue>
int main() {
   std::vector<int> v = {1,2,3,4};
   std::queue s{v};    // guide #1 deduces std::queue<int, vector<int>>
}