STD::PRIORITY_QUEUE(3)

🌸 std::priority_queue< _Tp, _Sequence, _Compare > 🌸

okay bestie, we're in the Library Functions Manual and this one is literally the moment πŸ’… β€” it's A standard container automatically sorting its contents. Yes, it sorts for you. No, you don't have to do anything. Iconic behaviour, honestly.


✨ NAME ✨

std::priority_queue< _Tp, _Sequence, _Compare > β€” a standard container that automatically sorts its contents πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <queue>

🌈 Public Types

  • typedef _Sequence::const_reference const_reference
  • typedef _Sequence container_type
  • typedef _Sequence::reference reference
  • typedef _Sequence::size_type size_type
  • typedef _Compare value_compare
  • typedef _Sequence::value_type value_type

πŸ’– Public Member Functions

  • template<typename _Seq = _Sequence, typename _Requires = typename enable_if<__and_<is_default_constructible<_Compare>, is_default_constructible<_Seq>>::value>::type> priority_queue () β€” the default constructor, it creates no elements (empty queen energy, we love a clean slate).
  • template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>> priority_queue (_InputIterator __first, _InputIterator __last, const _Alloc &__alloc)
  • template<typename _InputIterator, typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, _Sequence &&__s, const _Alloc &__alloc)
  • template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Alloc &__alloc)
  • template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Sequence &__s, const _Alloc &__alloc)
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (const _Alloc &__a)
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (const _Compare &__x, _Sequence &&__c, const _Alloc &__a)
  • priority_queue (const _Compare &__x, _Sequence &&__s=_Sequence())
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (const _Compare &__x, const _Alloc &__a)
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (const _Compare &__x, const _Sequence &__c, const _Alloc &__a)
  • priority_queue (const _Compare &__x, const _Sequence &__s)
  • priority_queue (const priority_queue &)=default
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (const priority_queue &__q, const _Alloc &__a)
  • priority_queue (priority_queue &&__q) noexcept(__and_<is_nothrow_move_constructible< _Sequence >, is_nothrow_move_constructible< _Compare > >::value)
  • template<typename _Alloc, typename _Requires = _Uses<_Alloc>> priority_queue (priority_queue &&__q, const _Alloc &__a)
  • template<typename... _Args> void emplace (_Args &&... __args)
  • bool empty () const
  • priority_queue & operator= (const priority_queue &)=default
  • priority_queue & operator= (priority_queue &&__q) noexcept(__and_<is_nothrow_move_assignable< _Sequence >, is_nothrow_move_assignable< _Compare > >::value)
  • void pop () β€” removes the first element 🫑
  • void push (const value_type &__x) β€” add data to the queue πŸ“₯
  • void push (value_type &&__x)
  • size_type size () const
  • void swap (priority_queue &__pq) noexcept(__and_<//c++1z or gnu++11 __is_nothrow_swappable< _Sequence >, __is_nothrow_swappable< _Compare > >::value)
  • const_reference top () const

and then these three range-builders hiding under top():

  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x=_Compare()) β€” builds a queue from a range 🌈
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Sequence &__s) β€” builds a queue from a range 🌈
  • template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>> priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, _Sequence &&__s) β€” builds a queue from a range 🌈

🧚 Protected Attributes

  • _Sequence c
  • _Compare comp

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
    less<typename _Sequence::value_type>>
class std::priority_queue< _Tp, _Sequence, _Compare >"A standard
container automatically sorting its contents.

πŸ’œ Template Parameters

  • _Tp β€” type of element.
  • _Sequence β€” type of underlying sequence, defaults to vector<_Tp>.
  • _Compare β€” comparison function object type, defaults to less<_Sequence::value_type>.

okay so listen. This is not a true container, bestie β€” it's an adaptor πŸͺ„. It holds another container and gives you a wrapper interface to that container. The wrapper is what enforces the priority-based sorting and the queue behaviour. Very few of the standard container/sequence interface requirements are met (e.g., iterators). Yeah. No iterators. We cope. 😭

The second template parameter defines the type of the underlying sequence/container. It defaults to std::vector, but it can be any type that supports front(), push_back, pop_back, and random-access iterators β€” such as std::deque or an appropriate user-defined type πŸ’…

The third template parameter supplies the means of making priority comparisons. It defaults to less<value_type> but can be anything defining a strict weak ordering.

Members not found in normal containers are container_type, which is a typedef for the second Sequence parameter, and push, pop, and top, which are standard queue operations.

Note πŸ“ No equality/comparison operators are provided for priority_queue. fr fr, none. Sorting of the elements takes place as they are added to, and removed from, the priority_queue using the priority_queue's member functions. If you access the elements by other means, and change their data such that the sorting order would be different, the priority_queue will not re-sort the elements for you. (How could it know to do so?) like bestie it literally cannot read your mind πŸ’€

πŸŽ€ Constructor & Destructor Documentation πŸŽ€

🌸 priority_queue ()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
    less<typename _Sequence::value_type>> template<typename _Seq =
    _Sequence, typename _Requires = typename
    enable_if<__and_<is_default_constructible<_Compare>,                   is_default_constructible<_Seq>>::value>::type>
    std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ()
    [inline]

Default constructor creates no elements. That's it, that's the whole vibe ✨

πŸ¦‹ priority_queue (_InputIterator __first, _InputIterator __last, const _Compare & __x = _Compare())

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
    less<typename _Sequence::value_type>> template<typename _InputIterator,
    typename = std::_RequireInputIter<_InputIterator>> std::priority_queue<
    _Tp, _Sequence, _Compare >::priority_queue (_InputIterator __first,
    _InputIterator __last, const _Compare & __x = _Compare()) [inline]

Builds a queue from a range 🌈

πŸ’– Parameters

  • __first β€” an input iterator.
  • __last β€” an input iterator.
  • __x β€” a comparison functor describing a strict weak ordering.
  • __s β€” an initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

πŸ¦‹ priority_queue (_InputIterator __first, _InputIterator __last, const _Compare & __x, const _Sequence & __s)

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
    less<typename _Sequence::value_type>> template<typename _InputIterator,
    typename = std::_RequireInputIter<_InputIterator>> std::priority_queue<
    _Tp, _Sequence, _Compare >::priority_queue (_InputIterator __first,
    _InputIterator __last, const _Compare & __x, const _Sequence & __s)
    [inline]

Builds a queue from a range 🌈

πŸ’– Parameters

  • __first β€” an input iterator.
  • __last β€” an input iterator.
  • __x β€” a comparison functor describing a strict weak ordering.
  • __s β€” an initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

πŸ¦‹ priority_queue (_InputIterator __first, _InputIterator __last, const _Compare & __x, _Sequence && __s)

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
    less<typename _Sequence::value_type>> template<typename _InputIterator,
    typename = std::_RequireInputIter<_InputIterator>> std::priority_queue<
    _Tp, _Sequence, _Compare >::priority_queue (_InputIterator __first,
    _InputIterator __last, const _Compare & __x, _Sequence && __s) [inline]

Builds a queue from a range 🌈

πŸ’– Parameters

  • __first β€” an input iterator.
  • __last β€” an input iterator.
  • __x β€” a comparison functor describing a strict weak ordering.
  • __s β€” an initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

References std::move().


okay that's part 1 bestie, stay tuned because there's more where that came from 🫢

πŸ’– Member Function Documentation πŸ’–

Okay bestie, this is where the magic happens. All the member functions of std::priority_queue are about to be served to you on a silver platter. No cap, every single one is here. Let's go! 🫢

🌸 empty() β€” the vibe check

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
       less<typename _Sequence::value_type>> bool std::priority_queue< _Tp,
       _Sequence, _Compare >::empty () const [inline],  [nodiscard]

Returns true if the queue is empty. That's it. It's [inline] and [nodiscard], so like, don't ignore the result bestie, that's rude. 😀

It's referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection(). Slay. ✨

πŸ’… pop() β€” removing the first element

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
       less<typename _Sequence::value_type>> void std::priority_queue< _Tp,
       _Sequence, _Compare >::pop () [inline]

Removes first element. This is a typical queue operation. It shrinks the queue by one. The time complexity of the operation depends on the underlying sequence. So like, it might be fast or slow depending on your _Sequence. πŸ’€

Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called. So don't be out here popping and then asking where your data went, because it's gone bestie. 😭

It's referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection(). Periodt. πŸ’…

πŸ¦‹ push() β€” adding data

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
       less<typename _Sequence::value_type>> void std::priority_queue< _Tp,
       _Sequence, _Compare >::push (const value_type & __x) [inline]

Add data to the queue. It's giving "here, take this". πŸŽ€

Parameters:

  • __x β€” Data to be added.

This is a typical queue operation. The time complexity of the operation depends on the underlying sequence. Again, it's all about that _Sequence. πŸ”₯

It's referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection(). Iykyk. 🌈

πŸŽ€ size() β€” counting the girlies

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
       less<typename _Sequence::value_type>> size_type std::priority_queue<
       _Tp, _Sequence, _Compare >::size () const [inline],  [nodiscard]

Returns the number of elements in the queue. So like, how many besties are in the queue? This tells you. It's [nodiscard] so don't ignore it. πŸ‘‘

⭐ top() β€” peeking at the main character

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare =
       less<typename _Sequence::value_type>> const_reference
       std::priority_queue< _Tp, _Sequence, _Compare >::top () const [inline],
       [nodiscard]

Returns a read-only (constant) reference to the data at the first element of the queue. So you can look but you can't touch. It's giving main character energy, but you're just observing. πŸ™ˆ

It's [nodiscard] and [inline]. Don't ignore the return value, bestie. πŸ’œ

It's referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection(). No cap. ✨


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code. So like, a robot wrote this but it's still iconic. πŸ’–


And that's the whole page bestie! This manual page was generated automatically by Doxygen for libstdc++ from the source code β€” that's the source/version. The date is not specified, but it's a classic. The footer is all about libstdc++ and std::priority_queue, but we don't need to copy it because you get the vibe. Stay iconic. πŸ“πŸ§šπŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms