priority_queue::push_range
needs to append_range
Section: 23.6.4.4 [priqueue.members] Status: C++23 Submitter: Casey Carter Opened: 2022-06-20 Last modified: 2023-11-22
Priority: 2
View all issues with C++23 status.
Discussion:
The push_range
members of the queue
(23.6.3.4 [queue.mod]) and
stack
(23.6.6.5 [stack.mod]) container adaptors are both specified as
"Effects: Equivalent to c.append_range(std::forward<R>(rg))
if that
is a valid expression, otherwise ranges::copy(rg, back_inserter(c))
.". For
priority_queue
, however, we have instead (23.6.4.4 [priqueue.members]):
-3- Effects: Insert all elements of
-4- Postconditions:rg
inc
.is_heap(c.begin(), c.end(), comp)
istrue
.
Since append_range
isn't one of the operations required of the underlying container,
"Insert all elements of rg
" must be implemented via potentially less efficient means.
It would be nice if this push_back
could take advantage of append_range
when it's available just as do the other two overloads.
[2022-07-08; Reflector poll]
Set priority to 2 after reflector poll.
[Issaquah 2023-02-08; LWG]
Unanimous consent to move to Immediate.
[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP.]
Proposed resolution:
This wording is relative to N4910.
Modify 23.6.4.4 [priqueue.members] as indicated:
template<container-compatible-range<T> R> void push_range(R&& rg);-3- Effects: Inserts all elements of
-4- Postconditions:rg
inc
viac.append_range(std::forward<R>(rg))
if that is a valid expression, orranges::copy(rg, back_inserter(c))
otherwise. Then restores the heap property as if bymake_heap(c.begin(), c.end(), comp)
.is_heap(c.begin(), c.end(), comp)
istrue
.