deductiongu...iority_queue(3)
π NAME π
deductiongu...iority_queue(3) β deduction guides for std::priority_queue, from the C++ Standard Libary (yes, the header spells it like that, and we are keeping it π
). This is the whole page for the std::priority_queue deduction guides, bestie. Defined in header <queue>. Overloads (1)β(6) are since C++17; overloads (7)β(9) are since C++23. No cap.
π¦ Synopsis π¦
Okay so here's the overload lineup. The arrows are literally βdeduces toβ, iykyk π
template< class Comp, class Container >
priority_queue( Comp, Container )
(1) (since C++17)
-> priority_queue<typename Container::value_type, Container, Comp>;
template< class InputIt,
class Comp = std::less</*iter-value-type*/<InputIt>>,
class Container = std::vector</*iter-value-type*/<InputIt> > >
priority_queue( InputIt, InputIt, Comp = Comp(), Container = Container() )
(2) (since C++17)
-> priority_queue</*iter-value-type*/<InputIt>, Container, Comp>;
template< class Comp, class Container, class Alloc >
priority_queue( Comp, Container, Alloc )
(3) (since C++17)
-> priority_queue<typename Container::value_type, Container, Comp>;
template< class InputIt, class Alloc >
priority_queue( InputIt, InputIt, Alloc )
(4) (since C++17)
-> priority_queue</*iter-value-type*/<InputIt>,
std::vector</*iter-value-type*/<InputIt>, Alloc>,
std::less</*iter-value-type*/<InputIt>>>;
template< class InputIt, class Comp, class Alloc >
priority_queue( InputIt, InputIt, Comp, Alloc )
(5) (since C++17)
-> priority_queue</*iter-value-type*/<InputIt>,
std::vector</*iter-value-type*/<InputIt>, Alloc>,
Comp>;
template< class InputIt, class Comp, class Container, class Alloc >
priority_queue( InputIt, InputIt, Comp, Container, Alloc )
(6) (since C++17)
-> priority_queue<typename Container::value_type, Container, Comp>;
template< ranges::input_range R,
class Comp = std::less<ranges::range_value_t<R>> >
priority_queue( std::from_range_t, R&&, Comp = Comp() )
(7) (since C++23)
-> priority_queue<ranges::range_value_t<R>,
std::vector<ranges::range_value_t<R>>,
Comp>;
template< ranges::input_range R, class Comp, class Alloc >
priority_queue( std::from_range_t, R&&, Comp, Alloc )
(8) (since C++23)
-> priority_queue<ranges::range_value_t<R>,
std::vector<ranges::range_value_t<R>, Alloc>,
Comp>;
template< ranges::input_range R, class Alloc >
priority_queue( std::from_range_t, R&&, Alloc )
(9) (since C++23)
-> priority_queue<ranges::range_value_t<R>,
std::vector<ranges::range_value_t<R>, Alloc>>;
These are the deduction guides that std::priority_queue gets, bestie:
(1-6)β allow deduction from the underlying container type and from an iterator range. For any typeIt,/*iter-value-type*/<It>denotestypename std::iterator_traits<It>::value_type.(7-9)β allow deduction from astd::from_range_ttag and aninput_range.
These overloads participate in overload resolution only if:
InputItsatisfiesLegacyInputIterator,Compdoes not satisfyAllocator,Containerdoes not satisfyAllocator,- for overloads
(4,5),(since C++23)AllocsatisfiesAllocator, and - for overloads
(3,6),std::uses_allocator_v<Container, Alloc>istrue.
Note: the extent to which the library determines that a type does not satisfyLegacyInputIteratoris 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 satisfyAllocatoris unspecified, except that as a minimum the member typeAlloc::value_typemust exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{})must be well-formed when treated as an unevaluated operand. π«Ά
π Notes π
Feature-test macro check, iykyk:
__cpp_lib_containers_rangesβ value202202L, std(C++23), feature: Ranges-aware construction and insertion; overloads(7-9)β¨
β¨ Example β¨
Okay bestie, run this code. Periodt π
// Run this code
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
int main()
{
const std::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 4
4 3 2 1
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Not me reading DRs for fun, but here we are π
LWG 3506β applied toC++17; behavior as published: deduction guides from iterator and allocator were missing; correct behavior: added.
That's the whole page, bestie π«Ά β from http://cppreference.com, version/date 2024.06.10, manual page deductiongu...iority_queue(3). Slay πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms