This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

### 250. splicing invalidates iterators

Section: 24.3.10.5 [list.ops] Status: CD1 Submitter: Brian Parker Opened: 2000-07-14 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [list.ops].

View all issues with CD1 status.

Discussion:

Section 24.3.10.5 [list.ops] states that

      void splice(iterator position, list<T, Allocator>& x);

invalidates all iterators and references to list `x`.

This is unnecessary and defeats an important feature of splice. In fact, the SGI STL guarantees that iterators to `x` remain valid after `splice`.

Proposed resolution:

Add a footnote to 24.3.10.5 [list.ops], paragraph 1:

> [Footnote: As specified in [default.con.req], paragraphs 4-5, the semantics described in this clause applies only to the case where allocators compare equal. --end footnote]

In 24.3.10.5 [list.ops], replace paragraph 4 with:

> Effects: Inserts the contents of x before position and x becomes empty. 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.

In 24.3.10.5 [list.ops], replace paragraph 7 with:

> 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.

In 24.3.10.5 [list.ops], replace paragraph 12 with:

> Requires: [first, last) is a valid range in x. The result is undefined if position is an iterator in the range [first, last). 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.

[pre-Copenhagen: Howard provided wording.]

Rationale:

The original proposed resolution said that iterators and references would remain "valid". The new proposed resolution clarifies what that means. Note that this only applies to the case of equal allocators. From [default.con.req] paragraph 4, the behavior of list when allocators compare nonequal is outside the scope of the standard.