# deduction guides for `std::priority_queue`

From cppreference.com
< cpp‎ | container‎ | priority queue

Defined in header `<queue>` |  |
template <class Compare, class Container> priority_queue(Compare, Container) -> priority_queue<typename Container::value_type, Container, Compare>; | (1) | (since C++17)
template<class InputIt, class Comp = std::less <typename std::iterator_traits <InputIt>::value_type>, class Container = std::vector <typename iterator_traits<InputIt>::value_type>> priority_queue(InputIt, InputIt, Comp = Comp(), Container = Container()) -> priority_queue<typename std::iterator_traits <InputIt>::value_type, Container, Comp>; | (2) | (since C++17)
template<class Comp, class Container, class Alloc> priority_queue(Comp, Container, Alloc) -> priority_queue<typename Container::value_type, Container, Comp>; | (2) | (since C++17)

These deduction guides are provided for std::priority_queue to allow deduction from underlying container type (overloads (1,3)) and from an iterator range (overload (2)) This overload only participates in overload resolution if `InputIt` satisfies LegacyInputIterator, `Alloc` satisfies Allocator, `Comp` does not satisfy Allocator, `Container` does not satisfy Allocator and, for overload (3), if std::uses_allocator_v <Container, Alloc> 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.

### Example

Run this code

    #include <vector>
    #include <queue>
    int main() {
       std::vector<int> v = {1,2,3,4};
       std::priority_queue pq1{v};                  // deduces std::priority_queue<int>
       std::priority_queue pq2{v.begin(), v.end()}; // deduces std::priority_queue<int>
    }

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/priority_queue/deduction_guides&oldid=104922"