Title
Why does forward_list::resize take the object to be copied by value?
Status
c++11
Section
[forward.list.modifiers]
Submitter
James McNellis

Created on 2010-07-16.00:00:00 last changed 144 months ago

Messages

Date: 2013-01-25.00:32:44

Proposed resolution:

  1. Change [forwardlist]/3, class template forward_list synopsis, as indicated:
    ...
    void resize(size_type sz);
    void resize(size_type sz, const value_type& c);
    void clear();
    ...
    
  2. Change [forwardlist.modifiers]/27 as indicated:
    	
    void resize(size_type sz);
    void resize(size_type sz, const value_type& c);
    

    27 Effects: If sz < distance(begin(), end()), erases the last distance(begin(), end()) - sz elements from the list. Otherwise, inserts sz - distance(begin(), end()) elements at the end of the list. For the first signature the inserted elements are default constructed, and for the second signature they are copies of c.

    28 - Requires: T shall be DefaultConstructible for the first form and it shall be CopyConstructible for the second form.

Date: 2013-01-25.00:32:44

[ Adopted at 2010-11 Batavia ]

Date: 2013-01-25.00:32:44

[ Post-Rapperswil ]

Daniel changed the P/R slightly, because one paragraph number has been changed since the issue had been submitted. He also added a similar Requires element that exists in all other containers with a resize member function. He deliberately did not touch the wrong usage of "default-constructed" because that will be taken care of by LWG issue 868.

Moved to Tentatively Ready with revised wording after 5 positive votes on c++std-lib.

Date: 2010-07-16.00:00:00

In N3092 [forwardlist.modifiers], the resize() member function is declared as:

void resize(size_type sz, value_type c); 

The other sequence containers (list, deque, and vector) take 'c' by const reference.

Is there a reason for this difference? If not, then resize() should be declared as:

void resize(size_type sz, const value_type& c); 

The declaration would need to be changed both at its declaration in the class definition at [forwardlist]/3 and where its behavior is specified at [forwardlist.modifiers]/22.

This would make forward_list consistent with the CD1 issue 679.

History
Date User Action Args
2013-01-25 00:32:44adminsetmessages: + msg6361
2013-01-25 00:32:44adminsetmessages: + msg6360
2013-01-25 00:32:44adminsetstatus: new -> c++11
2010-10-21 18:28:33adminsetmessages: + msg1639
2010-07-16 00:00:00admincreate