Title
assign() overspecified for sequence containers
Status
c++14
Section
[sequences]
Submitter
Jonathan Wakely

Created on 2012-10-31.00:00:00 last changed 122 months ago

Messages

Date: 2013-04-19.22:36:19

Proposed resolution:

This wording is relative to N3376.

  1. Edit [deque.cons] to remove everything after paragraph 10:

    template <class InputIterator>
    void assign(InputIterator first, InputIterator last);
    

    -11- Effects:

    erase(begin(), end());
    insert(begin(), first, last);
    
    void assign(size_type n, const T& t);
    

    -12- Effects:

    erase(begin(), end());
    insert(begin(), n, t);
    
  2. Edit [forwardlist.cons] to remove everything after paragraph 10:

    template <class InputIterator>
    void assign(InputIterator first, InputIterator last);
    

    -11- Effects: clear(); insert_after(before_begin(), first, last);

    void assign(size_type n, const T& t);
    

    -12- Effects: clear(); insert_after(before_begin(), n, t);

  3. Edit [list.cons] to remove everything after paragraph 10:

    template <class InputIterator>
    void assign(InputIterator first, InputIterator last);
    

    -11- Effects: Replaces the contents of the list with the range [first, last).

    void assign(size_type n, const T& t);
    

    -12- Effects: Replaces the contents of the list with n copies of t.

  4. Edit [vector.cons] to remove everything after paragraph 10:

    template <class InputIterator>
    void assign(InputIterator first, InputIterator last);
    

    -11- Effects:

    erase(begin(), end());
    insert(begin(), first, last);
    
    void assign(size_type n, const T& t);
    

    -12- Effects:

    erase(begin(), end());
    insert(begin(), n, t);
    
Date: 2013-04-20.00:00:00

[ 2013-04-20 Bristol ]

Date: 2013-03-15.00:00:00

[ 2013-03-15 Issues Teleconference ]

Moved to Tentatively Ready.

Date: 2012-10-31.00:00:00

DR 704 ensures allocator-aware containers can reuse existing elements during copy/move assignment, and sequence containers can do the same for assign().

But apart from std::list (which was changed by DR 320) the sequence containers define the Effects of assign() in terms of clear() followed by insert. A user-defined allocator can easily tell whether all old elements are cleared and then new elements inserted or whether existing elements are assigned to, so those Effects clauses cannot be ignored via the as-if rule.

The descriptions of the assign() members for deque, forward_list and vector should be removed. Their intended effects are entirely described by the sequence container requirements table, and the specific definitions of them are worse than redundant, they're contradictory (if the operations are defined in terms of erase and insert then there's no need for elements to be assignable.) The descriptions of assign() for list are correct but redundant, so should be removed too.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2013-04-25 19:07:07adminsetstatus: voting -> wp
2013-04-19 22:36:19adminsetmessages: + msg6487
2013-04-19 22:36:19adminsetstatus: ready -> voting
2013-03-18 14:33:00adminsetmessages: + msg6424
2013-03-18 13:02:36adminsetstatus: new -> ready
2012-11-01 21:52:13adminsetmessages: + msg6231
2012-10-31 00:00:00admincreate