std::priority_queue<T,Container,Compare>:: priority_queue
|
priority_queue
(
)
:
priority_queue
(
Compare
(
)
, Container
(
)
)
{
}
|
(1) | (C++11부터) |
|
explicit
priority_queue
(
const
Compare
&
compare
)
: priority_queue ( compare, Container ( ) ) { } |
(2) | (C++11부터) |
| (3) | ||
|
explicit
priority_queue
(
const
Compare
&
compare
=
Compare
(
)
,
const Container & cont = Container ( ) ) ; |
(C++11 이전) | |
|
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont
)
;
|
(C++11 이후) | |
|
priority_queue
(
const
Compare
&
compare, Container
&&
cont
)
;
|
(4) | (C++11부터) |
|
priority_queue
(
const
priority_queue
&
other
)
;
|
(5) | |
|
priority_queue
(
priority_queue
&&
other
)
;
|
(6) | (C++11부터) |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(7) | (C++11부터) |
| (8) | ||
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(C++11 이전) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(C++11 이후) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(9) | (C++11 이후) |
|
template
<
class
Alloc
>
explicit priority_queue ( const Alloc & alloc ) ; |
(10) | (C++11 이후) |
|
template
<
class
Alloc
>
priority_queue ( const Compare & compare, const Alloc & alloc ) ; |
(11) | (C++11 이후) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont,
|
(12) | (C++11 이후) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare, Container
&&
cont,
|
(13) | (C++11 이후) |
|
template
<
class
Alloc
>
priority_queue ( const priority_queue & other, const Alloc & alloc ) ; |
(14) | (C++11 이후) |
|
template
<
class
Alloc
>
priority_queue ( priority_queue && other, const Alloc & alloc ) ; |
(15) | (C++11 이후) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue ( InputIt first, InputIt last, const Alloc & alloc ) ; |
(16) | (C++11 이후) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(17) | (C++11부터) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(18) | (C++11 이후) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(19) | (C++11 이후) |
|
template
<
container-compatible-range
<
T
>
R
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(20) | (C++23 이후) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(21) | (C++23부터) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue ( std:: from_range_t , R && rg, const Alloc & alloc ) ; |
(22) | (C++23부터) |
다양한 데이터 소스로부터 컨테이너 어댑터의 새로운 기반 컨테이너를 생성합니다.
구현이 어떤 타입이 LegacyInputIterator 요구사항을 만족하는지 확인하는 방법은 지정되지 않았으나, 정수 타입들은 반드시 거부되어야 합니다.
목차 |
매개변수
| alloc | - | 기본 컨테이너의 모든 메모리 할당에 사용할 할당자 |
| other | - | 기본 컨테이너를 초기화하는 데 소스로 사용할 다른 컨테이너 어댑터 |
| cont | - | 기본 컨테이너를 초기화하는 데 소스로 사용할 컨테이너 |
| compare | - | 기본 비교 함수 객체를 초기화할 비교 함수 객체 |
| first, last | - | 초기화할 요소들의 범위 를 정의하는 반복자 쌍 |
| rg | - |
컨테이너 호환 범위
, 즉 요소들이
T
로 변환 가능한
input_range
|
| 타입 요구사항 | ||
-
Alloc
는
Allocator
요구사항을 충족해야 함
|
||
-
Compare
는
Compare
요구사항을 충족해야 함
|
||
-
Container
는
Container
요구사항을 충족해야 함. 할당자 확장 생성자는
Container
가
AllocatorAwareContainer
요구사항을 충족할 때만 정의됨
|
||
-
InputIt
는
LegacyInputIterator
요구사항을 충족해야 함
|
||
복잡도
value_type
생성자 호출, 여기서
N
은
cont.
size
(
)
입니다.
value_type
생성자 호출, 여기서
N
은
cont.
size
(
)
이고
M
은
std::
distance
(
first, last
)
입니다.
Alloc
가
other
의 할당자와 동일하게 비교되는 경우 상수 시간. 그렇지 않은 경우
other
의 크기에 선형 시간.
value_type
생성자 호출(
Alloc
이
other
의 할당자와 동일하지 않은 경우 존재함), 여기서
N
은
cont.
size
(
)
이고
M
은
std::
distance
(
first, last
)
입니다.
| 이 섹션은 불완전합니다 |
참고 사항
| Feature-test 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 생성 및 삽입; 오버로드 ( 20-22 ) |
예제
#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'; // 사용자 정의 비교자 데모: 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 범위 인식 생성자 }
출력:
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)
결함 보고서
다음 동작 변경 결함 보고서는 이전에 게시된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| P0935R0 | C++11 | 기본 생성자와 생성자 (4) 가 explicit였음 | implicit로 변경됨 |
| LWG 3506 | C++11 | allocator-extended iterator-pair 생성자가 누락됨 | 추가됨 |
| LWG 3522 | C++11 | iterator-pair 생성자에 대한 제약 조건이 누락됨 | 추가됨 |
| LWG 3529 | C++11 |
iterator 쌍으로부터의 생성이
insert
를 호출함
|
iterator들로부터 컨테이너를 생성함 |
참고 항목
|
컨테이너 어댑터에 값을 할당합니다
(public member function) |