2853. Possible inconsistency in specification of erase in [vector.modifiers]

Section: 23.3.11.5 [vector.modifiers] Status: C++17 Submitter: Gerard Stone Opened: 2017-01-16 Last modified: 2020-09-06

Priority: 0

View all other issues in [vector.modifiers].

View all issues with C++17 status.

Discussion:

In Table 87 (Sequence container requirements) erase(q) and erase(q1, q2) functions have the following requirements:

For vector and deque, T shall be MoveAssignable.

On the other hand, section [vector.modifiers] has the following specification for erase functions (emphasis mine):

Throws: Nothing unless an exception is thrown by the copy constructor, move constructor, assignment operator, or move assignment operator of T.

Note that Table 87 requires T to be only MoveAssignable, it says nothing about T being copy- or move-constructible. It also says nothing about T being CopyInsertable and MoveInsertable, so why is this even there? The only reason might be so that vector could shrink, but in this case T should be required to be MoveInsertable or CopyInsertable into vector.

On the other hand, we expect that vector will neither allocate, nor deallocate any memory during this operation, because in Effects it is specified that iterators/references shall be invalidated at or after the point of the erase.

So to avoid any confusion, the proposed resolution is to remove mentions of T's copy/move constructors from [vector.modifiers] paragraph 5.

[2017-01-27 Telecon]

Priority 0

Proposed resolution:

This wording is relative to N4618.

  1. Edit 23.3.11.5 [vector.modifiers] p5 as indicated:

    iterator erase(const_iterator position);
    iterator erase(const_iterator first, const_iterator last);
    void pop_back();
    

    -3- Effects: Invalidates iterators and references at or after the point of the erase.

    -4- Complexity: The destructor of T is called the number of times equal to the number of the elements erased, but the assignment operator of T is called the number of times equal to the number of elements in the vector after the erased elements.

    -5- Throws: Nothing unless an exception is thrown by the copy constructor, move constructor, assignment operator, or move assignment operator of T.