Created on 2021-03-01.00:00:00 last changed 13 months ago
Proposed resolution:
This wording is relative to N4878.
Edit [priqueue.overview] as indicated:
template<class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare()); 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, Container&& y= Compare()= Container());
Edit [priqueue.cons] as indicated:
template<class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare());Preconditions:
x
defines a strict weak ordering ([alg.sorting]).Effects: Initializes
c
withfirst
as the first argument andlast
as the second argument, and initializescomp
withx
; then callsmake_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());Preconditions:
x
defines a strict weak ordering ([alg.sorting]).Effects: Initializes
comp
withx
andc
withy
(copy constructing or move constructing as appropriate); callsc.insert(c.end(), first, last)
; and finally callsmake_heap(c.begin(), c.end(), comp)
.
[ 2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting → WP. ]
[ 2021-03-12; Reflector poll ]
Set status to Tentatively Ready after five votes in favour during reflector poll.
Tim's new constructors for priority_queue
(LWG 3506)
are specified so that when you construct
auto pq = PQ(first, last, a);
it calls this new-in-LWG3506 constructor:
template<class InputIterator, class Alloc> priority_queue(InputIterator first, InputIterator last, const Alloc& a);Effects: Initializes
c
withfirst
as the first argument,last
as the second argument, anda
as the third argument, and value-initializescomp
; callsmake_heap(c.begin(), c.end(), comp)
.
But the pre-existing constructors are specified so that when you construct
auto pq = PQ(first, last);
it calls this pre-existing constructor:
template<class InputIterator> priority_queue(InputIterator first, InputIterator last, const Compare& x = Compare(), Container&& y = Container());Preconditions:
x
defines a strict weak ordering ([alg.sorting]).Effects: Initializes
comp
withx
andc
withy
(copy constructing or move constructing as appropriate); callsc.insert(c.end(), first, last)
; and finally callsmake_heap(c.begin(), c.end(), comp)
.
In other words,
auto pq = PQ(first, last);
will default-construct a Container
,
then move-construct c
from that object,
then c.insert(first, last)
,
and finally make_heap
.
But our new
auto pq = PQ(first, last, a);
will simply construct c
with (first, last)
,
then make_heap
.
The latter is obviously better.
Also, Corentin's P1425R3
specifies the new iterator-pair constructors for
stack
and queue
to construct c
from (first, last)
. Good.
LWG should refactor the existing constructor overload set so that
the existing non-allocator-taking constructors simply construct c
from (first, last)
.
This will improve consistency with the resolutions of LWG3506 and P1425,
and reduce the surprise factor for users.
History | |||
---|---|---|---|
Date | User | Action | Args |
2023-11-22 15:47:43 | admin | set | status: wp -> c++23 |
2021-06-07 16:58:04 | admin | set | messages: + msg11899 |
2021-06-07 16:58:04 | admin | set | status: voting -> wp |
2021-05-26 21:11:22 | admin | set | status: ready -> voting |
2021-03-12 15:11:10 | admin | set | messages: + msg11738 |
2021-03-12 15:11:10 | admin | set | status: new -> ready |
2021-03-01 15:09:10 | admin | set | messages: + msg11721 |
2021-03-01 00:00:00 | admin | create |