list splice
functions should use addressof
Section: 23.3.7.6 [forward.list.ops], 23.3.9.5 [list.ops] Status: C++20 Submitter: Jonathan Wakely Opened: 2017-09-05 Last modified: 2023-02-07
Priority: 0
View all other issues in [forward.list.ops].
View all issues with C++20 status.
Discussion:
[forwardlist.ops] p1 and 23.3.9.5 [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)
.
[ 2017-11-03 Moved to Tentatively Ready after 9 positive votes for P0 on c++std-lib. ]
[2018-3-17 Adopted in Jacksonville]
Proposed resolution:
This wording is relative to N4687.
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
isbefore_begin()
or is a dereferenceable iterator in the range[begin(), end())
.get_allocator() == x.get_allocator()
..
&addressof(x) != this
Edit 23.3.9.5 [list.ops] p3 as indicated:
void splice(const_iterator position, list& x); void splice(const_iterator position, list&& x);-3- Requires:
.
&addressof(x) != this
Edit 23.3.9.5 [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:
-23- Effects: Ifcomp
shall define a strict weak ordering (26.8 [alg.sorting]), and both the list and the argument list shall be sorted according to this ordering.(
does nothing; otherwise, merges the two sorted ranges&addressof(x) == this)[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 bycomp
; that is, for every iteratori
, in the range other than the first, the conditioncomp(*i, *(i - 1))
will befalse
. Pointers and references to the moved elements ofx
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 intox
. -24- Remarks: Stable (16.4.6.8 [algorithm.stable]). If(
the range&addressof(x) != this)[x.begin(), x.end())
is empty after the merge. No elements are copied by this operation. The behavior is undefined ifget_allocator() != x.get_allocator()
. -25- Complexity: At mostsize() + x.size() - 1
applications ofcomp
if(
; otherwise, no applications of&addressof(x) != this)comp
are performed. If an exception is thrown other than by a comparison there are no effects.