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

### 2209. `assign()` overspecified for sequence containers

Section: 22.3 [sequences] Status: C++14 Submitter: Jonathan Wakely Opened: 2012-10-31 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [sequences].

View all issues with C++14 status.

Discussion:

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.

[2013-03-15 Issues Teleconference]

Moved to Tentatively Ready.

[2013-04-20 Bristol]

Proposed resolution:

This wording is relative to N3376.

1. Edit 22.3.8.2 [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 22.3.10.2 [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 22.3.11.2 [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);