Title
remove can't swap but note says it might
Status
c++14
Section
[alg.remove]
Submitter
Howard Hinnant

Created on 2011-12-07.00:00:00 last changed 123 months ago

Messages

Date: 2012-11-03.04:16:46

Proposed resolution:

This wording is relative to the FDIS.

Change [alg.remove] as indicated:

template<class ForwardIterator, class T>
  ForwardIterator remove(ForwardIterator first, ForwardIterator last,
                         const T& value);

template<class ForwardIterator, class Predicate>
  ForwardIterator remove_if(ForwardIterator first, ForwardIterator last,
                            Predicate pred);

[…]

-6-Note: each element in the range [ret,last), where ret is the returned value, has a valid but unspecified state, because the algorithms can eliminate elements by swapping with or moving from elements that were originally in that range.

Date: 2012-11-03.04:16:46

[ 2012, Portland: applied to WP ]

Date: 2012-02-12.18:36:43

[ 2012, Kona ]

Move to Ready.

Alisdair notes we could extend permission to use swap if it is available, but there is no interest. Accept the proposed resolution as written.

Date: 2011-12-07.00:00:00

[alg.remove]/p1 says:

1 Requires: The type of *first shall satisfy the MoveAssignable requirements (Table 22).

This means that remove/remove_if can only use move assignment to permute the sequence. But then [alg.remove]/p6 (non-normatively) contradicts p1:

6 Note: each element in the range [ret,last), where ret is the returned value, has a valid but unspecified state, because the algorithms can eliminate elements by swapping with or moving from elements that were originally in that range.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2012-11-03 04:16:46adminsetmessages: + msg6272
2012-10-25 12:46:45adminsetstatus: voting -> wp
2012-10-16 15:35:12adminsetstatus: ready -> voting
2012-02-12 18:36:43adminsetmessages: + msg6005
2012-02-12 18:36:43adminsetstatus: new -> ready
2011-12-08 22:24:12adminsetmessages: + msg5958
2011-12-07 00:00:00admincreate