std::priority_queue(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::priority_queue| Member functions | ||||
| Element access | ||||
| Capacity | ||||
| Modifiers | ||||
(C++23) | ||||
(C++11) | ||||
(C++11) | ||||
| Non-member functions | ||||
(C++11) | ||||
| Helper classes | ||||
| Deduction guides(C++17) |
Defined in header <queue> | ||
template<class Comp,class Container> priority_queue( Comp, Container) | (1) | (since C++17) |
template<class InputIt, class Comp=std::less</*iter-val-t*/<InputIt>>, | (2) | (since C++17) |
template<class Comp,class Container,class Alloc> priority_queue( Comp, Container, Alloc) | (3) | (since C++17) |
template<class InputIt,class Alloc> priority_queue( InputIt, InputIt, Alloc) | (4) | (since C++17) |
template<class InputIt,class Comp,class Alloc> priority_queue( InputIt, InputIt, Comp, Alloc) | (5) | (since C++17) |
template<class InputIt,class Comp,class Container,class Alloc> priority_queue( InputIt, InputIt, Comp, Container, Alloc) | (6) | (since C++17) |
template<ranges::input_range R, class Comp=std::less<ranges::range_value_t<R>>> | (7) | (since C++23) |
template<ranges::input_range R,class Comp,class Alloc> priority_queue(std::from_range_t, R&&, Comp, Alloc) | (8) | (since C++23) |
template<ranges::input_range R,class Alloc> priority_queue(std::from_range_t, R&&, Alloc) | (9) | (since C++23) |
Exposition-only helper type aliases | ||
template<class InputIt> using/*iter-val-t*/= | (exposition only*) | |
The followingdeduction guides are provided forstd::priority_queue:
These overloads participate in overload resolution only if
InputIt satisfiesLegacyInputIterator,Comp does not satisfyAllocator,Container does not satisfyAllocator,Alloc satisfiesAllocator, andNote: the extent to which the library determines that a type does not satisfyLegacyInputIterator 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 satisfyAllocator is unspecified, except that as a minimum the member typeAlloc::value_type must exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as an unevaluated operand.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges | 202202L | (C++23) | Ranges-aware construction and insertion; overloads(7-9) |
#include <functional>#include <iostream>#include <queue>#include <vector> int main(){conststd::vector<int> v={1,2,3,4};std::priority_queue pq1{std::greater<int>{}, v};// deduces std::priority_queue<// int, std::vector<int>,// std::greater<int>>for(;!pq1.empty(); pq1.pop())std::cout<< pq1.top()<<' ';std::cout<<'\n'; std::priority_queue pq2{v.begin(), v.end()};// deduces std::priority_queue<int> for(;!pq2.empty(); pq2.pop())std::cout<< pq2.top()<<' ';std::cout<<'\n';}
Output:
1 2 3 44 3 2 1
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3506 | C++17 | deduction guides from iterator and allocator were missing | added,(4-6) |