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_referencetypedef _Sequence container_typetypedef _Sequence::reference referencetypedef _Sequence::size_type size_typetypedef _Compare value_comparetypedef _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 &)=defaulttemplate<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 () constpriority_queue & operator= (const priority_queue &)=defaultpriority_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 () constvoid 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 tovector<_Tp>._Compareβ comparison function object type, defaults toless<_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 forpriority_queue. fr fr, none. Sorting of the elements takes place as they are added to, and removed from, thepriority_queueusing thepriority_queue's member functions. If you access the elements by other means, and change their data such that the sorting order would be different, thepriority_queuewill 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