Title
list splice functions should use addressof
Status
c++20
Section
[forward.list.ops][list.ops]
Submitter
Jonathan Wakely

Created on 2017-09-05.00:00:00 last changed 46 months ago

Messages

Date: 2018-03-18.16:03:30

Proposed resolution:

This wording is relative to N4687.

  1. Edit [forwardlist.ops] p1 as indicated:

    void splice_after(const_iterator position, forward_list& x);
    void splice_after(const_iterator position, forward_list&& x);
    

    -1- Requires: position is before_begin() or is a dereferenceable iterator in the range [begin(), end()). get_allocator() == x.get_allocator(). &addressof(x) != this.

  2. Edit [list.ops] p3 as indicated:

    void splice(const_iterator position, list& x);
    void splice(const_iterator position, list&& x);
    

    -3- Requires: &addressof(x) != this.

  3. Edit [list.ops] p3 as indicated:

    template <class Compare> void merge(list& x, Compare comp);
    template <class Compare> void merge(list&& x, Compare comp);
    

    -22- Requires: comp shall define a strict weak ordering ([alg.sorting]), and both the list and the argument list shall be sorted according to this ordering.

    -23- Effects: If (&addressof(x) == this) does nothing; otherwise, merges the two sorted ranges [begin(), end()) and [x.begin(), x.end()). The result is a range in which the elements will be sorted in non-decreasing order according to the ordering defined by comp; that is, for every iterator i, in the range other than the first, the condition comp(*i, *(i - 1)) will be false. Pointers and references to the moved elements of x now refer to those same elements but as members of *this. Iterators referring to the moved elements will continue to refer to their elements, but they now behave as iterators into *this, not into x.

    -24- Remarks: Stable ([algorithm.stable]). If (&addressof(x) != this) the range [x.begin(), x.end()) is empty after the merge. No elements are copied by this operation. The behavior is undefined if get_allocator() != x.get_allocator().

    -25- Complexity: At most size() + x.size() - 1 applications of comp if (&addressof(x) != this); otherwise, no applications of comp are performed. If an exception is thrown other than by a comparison there are no effects.

Date: 2018-03-17.00:00:00

[ 2018-3-17 Adopted in Jacksonville ]

Date: 2017-11-03.00:00:00

[ 2017-11-03 Moved to Tentatively Ready after 9 positive votes for P0 on c++std-lib. ]

Date: 2017-09-05.00:00:00

[forwardlist.ops] p1 and [list.ops] p3 say &x != this, but should use addressof. We really need front matter saying that when the library says &x it means std::addressof(x).

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2018-03-18 16:03:30adminsetmessages: + msg9743
2018-03-18 16:03:30adminsetstatus: voting -> wp
2018-02-12 01:13:49adminsetstatus: ready -> voting
2017-11-03 17:20:12adminsetmessages: + msg9503
2017-11-03 17:20:12adminsetstatus: new -> ready
2017-09-10 12:48:35adminsetmessages: + msg9459
2017-09-05 00:00:00admincreate