std::priority_queue<T,Container,Compare>:: priority_queue
|
priority_queue
(
)
:
priority_queue
(
Compare
(
)
, Container
(
)
)
{
}
|
(1) | (seit C++11) |
|
explicit
priority_queue
(
const
Compare
&
compare
)
: priority_queue ( compare, Container ( ) ) { } |
(2) | (seit C++11) |
| (3) | ||
|
explicit
priority_queue
(
const
Compare
&
compare
=
Compare
(
)
,
const Container & cont = Container ( ) ) ; |
(bis C++11) | |
|
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont
)
;
|
(seit C++11) | |
|
priority_queue
(
const
Compare
&
compare, Container
&&
cont
)
;
|
(4) | (seit C++11) |
|
priority_queue
(
const
priority_queue
&
other
)
;
|
(5) | |
|
priority_queue
(
priority_queue
&&
other
)
;
|
(6) | (seit C++11) |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(7) | (seit C++11) |
| (8) | ||
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(bis C++11) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(seit C++11) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(9) | (seit C++11) |
|
template
<
class
Alloc
>
explicit priority_queue ( const Alloc & alloc ) ; |
(10) | (seit C++11) |
|
template
<
class
Alloc
>
priority_queue ( const Compare & compare, const Alloc & alloc ) ; |
(11) | (seit C++11) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont,
|
(12) | (seit C++11) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare, Container
&&
cont,
|
(13) | (seit C++11) |
|
template
<
class
Alloc
>
priority_queue ( const priority_queue & other, const Alloc & alloc ) ; |
(14) | (seit C++11) |
|
template
<
class
Alloc
>
priority_queue ( priority_queue && other, const Alloc & alloc ) ; |
(15) | (seit C++11) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue ( InputIt first, InputIt last, const Alloc & alloc ) ; |
(16) | (seit C++11) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(17) | (seit C++11) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(18) | (seit C++11) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(19) | (seit C++11) |
|
template
<
container-compatible-range
<
T
>
R
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(20) | (seit C++23) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(21) | (seit C++23) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue ( std:: from_range_t , R && rg, const Alloc & alloc ) ; |
(22) | (seit C++23) |
Konstruiert einen neuen zugrundeliegenden Container des Container-Adapters aus einer Vielzahl von Datenquellen.
InputIt
die Anforderungen an
LegacyInputIterator
erfüllt.
Beachten Sie, dass die Art und Weise, wie eine Implementierung prüft, ob ein Typ die Anforderungen eines LegacyInputIterator erfüllt, nicht spezifiziert ist, außer dass Integraltypen abgelehnt werden müssen.
Inhaltsverzeichnis |
Parameter
| alloc | - | Allokator, der für alle Speicherallokationen des zugrundeliegenden Containers verwendet wird |
| other | - | ein weiterer Container-Adapter, der als Quelle zur Initialisierung des zugrundeliegenden Containers dient |
| cont | - | Container, der als Quelle zur Initialisierung des zugrundeliegenden Containers verwendet wird |
| compare | - | das Vergleichsfunktionsobjekt zur Initialisierung des zugrundeliegenden Vergleichsfunktors |
| first, last | - | das Iteratorpaar, das den Bereich der zu initialisierenden Elemente definiert |
| rg | - |
ein
container-kompatibler Bereich
, also ein
input_range
, dessen Elemente in
T
konvertierbar sind
|
| Typanforderungen | ||
-
Alloc
muss die Anforderungen von
Allocator
erfüllen.
|
||
-
Compare
muss die Anforderungen von
Compare
erfüllen.
|
||
-
Container
muss die Anforderungen von
Container
erfüllen. Die Allokator-erweiterten Konstruktoren sind nur definiert, wenn
Container
die Anforderungen von
AllocatorAwareContainer
erfüllt.
|
||
-
InputIt
muss die Anforderungen von
LegacyInputIterator
erfüllen.
|
||
Komplexität
value_type
, wobei
N
cont.
size
(
)
ist.
value_type
, wobei
N
gleich
cont.
size
(
)
und
M
gleich
std::
distance
(
first, last
)
ist.
Alloc
gleich dem Allokator von
other
ist. Linear in der Größe von
other
andernfalls.
value_type
(vorhanden falls
Alloc
nicht gleich dem Allokator von
other
ist), wobei
N
gleich
cont.
size
(
)
und
M
gleich
std::
distance
(
first, last
)
ist.
value_type
, wobei
N
gleich
ranges::
distance
(
rg
)
ist.
| Dieser Abschnitt ist unvollständig |
Hinweise
| Feature-Test Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-bewusste Konstruktion und Einfügung; Überladungen ( 20-22 ) |
Beispiel
#include <complex> #include <functional> #include <iostream> #include <queue> #include <vector> int main() { std::priority_queue<int> pq1; pq1.push(5); std::cout << "pq1.size() = " << pq1.size() << '\n'; std::priority_queue<int> pq2 {pq1}; std::cout << "pq2.size() = " << pq2.size() << '\n'; std::vector<int> vec {3, 1, 4, 1, 5}; std::priority_queue<int> pq3 {std::less<int>(), vec}; std::cout << "pq3.size() = " << pq3.size() << '\n'; for (std::cout << "pq3 : "; !pq3.empty(); pq3.pop()) std::cout << pq3.top() << ' '; std::cout << '\n'; // Demo With Custom Comparator: using my_value_t = std::complex<double>; using my_container_t = std::vector<my_value_t>; auto my_comp = [](const my_value_t& z1, const my_value_t& z2) { return z2.real() < z1.real(); }; std::priority_queue<my_value_t, my_container_t, decltype(my_comp)> pq4{my_comp}; using namespace std::complex_literals; pq4.push(5.0 + 1i); pq4.push(3.0 + 2i); pq4.push(7.0 + 3i); for (; !pq4.empty(); pq4.pop()) { const auto& z = pq4.top(); std::cout << "pq4.top() = " << z << '\n'; } // TODO: C++23 range-aware ctors }
Ausgabe:
pq1.size() = 1 pq2.size() = 1 pq3.size() = 5 pq3 : 5 4 3 1 1 pq4.top() = (3,2) pq4.top() = (5,1) pq4.top() = (7,3)
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrektes Verhalten |
|---|---|---|---|
| P0935R0 | C++11 | Standardkonstruktor und Konstruktor (4) waren explizit | implizit gemacht |
| LWG 3506 | C++11 | Allokator-erweiterte Iterator-Paar-Konstruktoren fehlten | hinzugefügt |
| LWG 3522 | C++11 | Einschränkungen für Iterator-Paar-Konstruktoren fehlten | hinzugefügt |
| LWG 3529 | C++11 |
Konstruktion aus einem Iterator-Paar rief
insert
auf
|
konstruiert den Container daraus |
Siehe auch
|
weist Werte dem Container-Adapter zu
(öffentliche Elementfunktion) |