Title
Possible inconsistency in specification of erase in [vector.modifiers]
Status
c++17
Section
[vector.modifiers]
Submitter
Gerard Stone

Created on 2017-01-16.00:00:00 last changed 90 months ago

Messages

Date: 2017-01-30.15:36:02

Proposed resolution:

This wording is relative to N4618.

  1. Edit [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.

Date: 2017-01-27.00:00:00

[ 2017-01-27 Telecon ]

Priority 0

Date: 2017-01-16.00:00:00

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.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2017-03-05 23:41:16adminsetstatus: ready -> wp
2017-01-30 15:36:02adminsetmessages: + msg8829
2017-01-30 15:36:02adminsetstatus: new -> ready
2017-01-25 19:39:26adminsetmessages: + msg8786
2017-01-16 00:00:00admincreate