Any sequence container with random access iterator and supporting operations front(), push_back() and pop_back() can be used to instantiate priority_queue. In particular, vector ([vector]) and deque ([deque]) can be used. Instantiating priority_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]).
namespace std { template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> > class priority_queue { public: typedef typename Container::value_type value_type; typedef typename Container::reference reference; typedef typename Container::const_reference const_reference; typedef typename Container::size_type size_type; typedef Container container_type; protected: Container c; Compare comp; public: priority_queue(const Compare& x, const Container&); explicit priority_queue(const Compare& x = Compare(), Container&& = Container()); template <class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x, const Container&); template <class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare(), Container&& = Container()); template <class Alloc> explicit priority_queue(const Alloc&); template <class Alloc> priority_queue(const Compare&, const Alloc&); template <class Alloc> priority_queue(const Compare&, const Container&, const Alloc&); template <class Alloc> priority_queue(const Compare&, Container&&, const Alloc&); template <class Alloc> priority_queue(const priority_queue&, const Alloc&); template <class Alloc> priority_queue(priority_queue&&, const Alloc&); bool empty() const { return c.empty(); } size_type size() const { return c.size(); } const_reference top() const { return c.front(); } void push(const value_type& x); void push(value_type&& x); template <class... Args> void emplace(Args&&... args); void pop(); void swap(priority_queue& q) noexcept( noexcept(swap(c, q.c)) && noexcept(swap(comp, q.comp))) { using std::swap; swap(c, q.c); swap(comp, q.comp); } }; template <class T, class Container, class Compare> void swap(priority_queue<T, Container, Compare>& x, priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y))); template <class T, class Container, class Compare, class Alloc> struct uses_allocator<priority_queue<T, Container, Compare>, Alloc> : uses_allocator<Container, Alloc>::type { }; }23.6.4.1 priority_queue constructors [priqueue.cons]
priority_queue(const Compare& x, const Container& y); explicit priority_queue(const Compare& x = Compare(), Container&& y = Container());
Effects: Initializes comp with x and c with y (copy constructing or move constructing as appropriate); calls make_heap(c.begin(), c.end(), comp).
template <class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x, const Container& y); template <class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare(), Container&& y = Container());
Effects: Initializes comp with x and c with y (copy constructing or move constructing as appropriate); calls c.insert(c.end(), first, last); and finally calls make_heap(c.begin(), c.end(), comp).
23.6.4.2 priority_queue constructors with allocators [priqueue.cons.alloc]If uses_allocator<container_type, Alloc>::value is false the constructors in this subclause shall not participate in overload resolution.
template <class Alloc> explicit priority_queue(const Alloc& a);
Effects: Initializes c with a and value-initializes comp.
template <class Alloc> priority_queue(const Compare& compare, const Alloc& a);
Effects: Initializes c with a and initializes comp with compare.
template <class Alloc> priority_queue(const Compare& compare, const Container& cont, const Alloc& a);
Effects: Initializes c with cont as the first argument and a as the second argument, and initializes comp with compare.
template <class Alloc> priority_queue(const Compare& compare, Container&& cont, const Alloc& a);
Effects: Initializes c with std::move(cont) as the first argument and a as the second argument, and initializes comp with compare.
template <class Alloc> priority_queue(const priority_queue& q, const Alloc& a);
Effects: Initializes c with q.c as the first argument and a as the second argument, and initializes comp with q.comp.
template <class Alloc> priority_queue(priority_queue&& q, const Alloc& a);
Effects: Initializes c with std::move(q.c) as the first argument and a as the second argument, and initializes comp with std::move(q.comp).
23.6.4.3 priority_queue members [priqueue.members] void push(const value_type& x);
Effects:
c.push_back(x); push_heap(c.begin(), c.end(), comp);
Effects:
c.push_back(std::move(x)); push_heap(c.begin(), c.end(), comp);
template <class... Args> void emplace(Args&&... args)
Effects:
c.emplace_back(std::forward<Args>(args)...); push_heap(c.begin(), c.end(), comp);
Effects:
pop_heap(c.begin(), c.end(), comp); c.pop_back();23.6.4.4 priority_queue specialized algorithms [priqueue.special]
template <class T, class Container, Compare> void swap(priority_queue<T, Container, Compare>& x, priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4