[priqueue.overview]

# 23 Containers library [[containers]](./#containers)

## 23.6 Container adaptors [[container.adaptors]](container.adaptors#priqueue.overview)

### 23.6.4 Class template priority_queue [[priority.queue]](priority.queue#priqueue.overview)

#### 23.6.4.1 Overview [priqueue.overview]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15993)

Any sequence container with random access iterator and supporting operationsfront(),push_back() andpop_back() can be used to instantiatepriority_queue[.](#1.sentence-1)

In particular,<vector> and<deque> can be used[.](#1.sentence-2)

Instantiatingpriority_queue also involves supplying a function or function object for making
priority comparisons; the library assumes that the function or function
object defines a [strict weak ordering](alg.sorting "26.8 Sorting and related operations [alg.sorting]")[.](#1.sentence-3)

namespace std {template<class T, class Container = vector<T>, class Compare = less<typename Container::value_type>>class priority_queue {public:using value_type = typename Container::value_type; using reference = typename Container::reference; using const_reference = typename Container::const_reference; using size_type = typename Container::size_type; using container_type = Container; using value_compare = Compare; protected: Container c;
 Compare comp; public:constexpr priority_queue() : priority_queue(Compare()) {}constexpr explicit priority_queue(const Compare& x) : priority_queue(x, Container()) {}constexpr priority_queue(const Compare& x, const Container&); constexpr priority_queue(const Compare& x, Container&&); template<class InputIterator>constexpr priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare()); template<class InputIterator>constexpr priority_queue(InputIterator first, InputIterator last, const Compare& x, const Container&); template<class InputIterator>constexpr priority_queue(InputIterator first, InputIterator last, const Compare& x,
 Container&&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>constexpr priority_queue(from_range_t, R&& rg, const Compare& x = Compare()); template<class Alloc> constexpr explicit priority_queue(const Alloc&); template<class Alloc> constexpr priority_queue(const Compare&, const Alloc&); template<class Alloc>constexpr priority_queue(const Compare&, const Container&, const Alloc&); template<class Alloc> constexpr priority_queue(const Compare&, Container&&, const Alloc&); template<class Alloc> constexpr priority_queue(const priority_queue&, const Alloc&); template<class Alloc> constexpr priority_queue(priority_queue&&, const Alloc&); template<class InputIterator, class Alloc>constexpr priority_queue(InputIterator, InputIterator, const Alloc&); template<class InputIterator, class Alloc>constexpr priority_queue(InputIterator, InputIterator, const Compare&, const Alloc&); template<class InputIterator, class Alloc>constexpr priority_queue(InputIterator, InputIterator, const Compare&, const Container&, const Alloc&); template<class InputIterator, class Alloc>constexpr priority_queue(InputIterator, InputIterator, const Compare&, Container&&, const Alloc&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R, class Alloc>constexpr priority_queue(from_range_t, R&& rg, const Compare&, const Alloc&); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R, class Alloc>constexpr priority_queue(from_range_t, R&& rg, const Alloc&); constexpr bool empty() const { return c.empty(); }constexpr size_type size() const { return c.size(); }constexpr const_reference top() const { return c.front(); }constexpr void push(const value_type& x); constexpr void push(value_type&& x); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>constexpr void push_range(R&& rg); template<class... Args> constexpr void emplace(Args&&... args); constexpr void pop(); constexpr void swap(priority_queue& q)noexcept(is_nothrow_swappable_v<Container> && is_nothrow_swappable_v<Compare>){ using std::swap; swap(c, q.c); swap(comp, q.comp); }}; template<class Compare, class Container> priority_queue(Compare, Container)-> priority_queue<typename Container::value_type, Container, Compare>; template<class InputIterator, class Compare = less<*iter-value-type*<InputIterator>>, class Container = vector<*iter-value-type*<InputIterator>>> priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())-> priority_queue<*iter-value-type*<InputIterator>, Container, Compare>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Compare = less<ranges::range_value_t<R>>> priority_queue(from_range_t, R&&, Compare = Compare())-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>>, Compare>; template<class Compare, class Container, class Allocator> priority_queue(Compare, Container, Allocator)-> priority_queue<typename Container::value_type, Container, Compare>; template<class InputIterator, class Allocator> priority_queue(InputIterator, InputIterator, Allocator)-> priority_queue<*iter-value-type*<InputIterator>,
 vector<*iter-value-type*<InputIterator>, Allocator>,
 less<*iter-value-type*<InputIterator>>>; template<class InputIterator, class Compare, class Allocator> priority_queue(InputIterator, InputIterator, Compare, Allocator)-> priority_queue<*iter-value-type*<InputIterator>,
 vector<*iter-value-type*<InputIterator>, Allocator>, Compare>; template<class InputIterator, class Compare, class Container, class Allocator> priority_queue(InputIterator, InputIterator, Compare, Container, Allocator)-> priority_queue<typename Container::value_type, Container, Compare>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Compare, class Allocator> priority_queue(from_range_t, R&&, Compare, Allocator)-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>,
 Compare>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Allocator> priority_queue(from_range_t, R&&, Allocator)-> priority_queue<ranges::range_value_t<R>, vector<ranges::range_value_t<R>, Allocator>>; // no equality is providedtemplate<class T, class Container, class Compare, class Alloc>struct uses_allocator<priority_queue<T, Container, Compare>, Alloc>: uses_allocator<Container, Alloc>::type { };}
