Title
Inconsistent return values for forward_list::insert_after
Status
c++11
Section
[forward.list.modifiers]
Submitter
Bo Persson

Created on 2009-11-25.00:00:00 last changed 161 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

In forward_list modifiers [forwardlist.modifiers] make the following modifications:

iterator insert_after(const_iterator position, size_type n, const T& x);

...

10 Returns: position. An iterator pointing to the last inserted copy of x or position if n == 0.

template <class InputIterator>
  iterator insert_after(const_iterator position, InputIterator first, InputIterator last);

...

13 Returns: position. An iterator pointing to the last inserted element or position if first == last.

iterator insert_after(const_iterator position, initializer_list<T> il);

...

15 Returns: position. An iterator pointing to the last inserted element or position if il is empty.

template <class... Args>
  iterator emplace_after(const_iterator position, Args&&... args);

...

17 ...

Returns: An iterator pointing to the new constructed element from args.

Date: 2010-03-15.00:00:00

[ 2010-03-15 Howard adds: ]

Wording updated and set to Ready.

Date: 2010-10-21.18:28:33

[ 2010 Pittsburgh: ]

We prefer to return an iterator to the last inserted element. Modify the proposed wording and then set to Ready.

Date: 2010-02-04.00:00:00

[ 2010-02-04 Nico provides wording. ]

Date: 2010-02-04.00:00:00

[ 2010-02-04 Howard adds: ]

I agree this inconsistency will be error prone and needs to be fixed. Additionally emplace_after's return value is unspecified.

Date: 2009-11-25.00:00:00

After applying LDR149, forward_list now has 5 overloads of insert_after, all returning an iterator.

However, two of those - inserting a single object - return "An iterator pointing to a copy of x [the inserted object]" while the other three - inserting zero or more objects - return an iterator equivalent to the position parameter, pointing before any possibly inserted objects.

Is this the intended change?

I don't really know what insert_after(position, empty_range) should really return, but always returning position seems less than useful.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 19:00:35adminsetstatus: ready -> wp
2010-10-21 18:28:33adminsetmessages: + msg1418
2010-10-21 18:28:33adminsetmessages: + msg1417
2010-10-21 18:28:33adminsetmessages: + msg1416
2010-10-21 18:28:33adminsetmessages: + msg1415
2010-10-21 18:28:33adminsetmessages: + msg1414
2009-11-25 00:00:00admincreate