Title
Carefully state effects of list::splice function
Status
nad
Section
[list.ops] [forward.list.ops]
Submitter
Arseny Klimovsky

Created on 2013-08-15.00:00:00 last changed 127 months ago

Messages

Date: 2013-09-26.11:12:18

Proposed resolution:

This wording is relative to N3691.

  1. Modify [forwardlist.ops] p6 as indicated:

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

    […]

    -6- Effects: Inserts the element following i into *this, following position, and removes it from x. The result is unchanged if &x == this and the following condition is satisfied: position == i or position == ++i. Pointers and references to *++i continue to refer to the same element but as a member of *this. Iterators to *++i continue to refer to the same element, but now behave as iterators into *this, not into x.

  2. Modify [list.ops] p7 as indicated:

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

    -7- Effects: Inserts an element pointed to by i from list x before position and removes the element from x. The result is unchanged if &x == this and the following condition is satisfied: position == i or position == ++i. Pointers and references to *i continue to refer to this same element but as a member of *this. Iterators to *i (including i itself) continue to refer to the same element, but now behave as iterators into *this, not into x.

Date: 2013-09-26.11:12:18

[ 2013-09 Chicago (late night issues) ]

Moved to NAD.

The condition under which the list is unchanged is not program code, so there is no undefined behavior to protect against. Rather, the precondition that the evaluation can be performed is implicit if determining when the condition applies.

Date: 2013-08-22.17:16:57

I think that the effects of list::splice function should be stated more carefully.

Function transferring a single element is described now in the following way ([list.ops] p7):

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

Effects: Inserts an element pointed to by i from list x before position and removes the element from x. The result is unchanged if position == i or position == ++i. Pointers and references to *i continue to refer to this same element but as a member of *this. Iterators to *i (including i itself) continue to refer to the same element, but now behave as iterators into *this, not into x.

But it is incorrect to talk about operator== for iterators that are not from the same container (after acceptance of N3066, [forward.iterators] p2). So, the text operates with an undefined behaviour.

One is formally allowed to have list implementation where two iterators from different lists return true to operator==. For example, this can only happen to non-dereferenceable iterators, and position and ++i can be non-dereferenceable. So, literally according to the standard, it is not allowed in this implementation to transfer such elements with splice function.

History
Date User Action Args
2013-09-26 11:12:18adminsetmessages: + msg6630
2013-09-26 11:12:18adminsetstatus: new -> nad
2013-08-20 19:41:21adminsetmessages: + msg6564
2013-08-15 00:00:00admincreate