Title
Does unique_copy() require CopyConstructible and Assignable?
Status
cd1
Section
[alg.unique]
Submitter
Angelika Langer

Created on 2000-05-15.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

[ CuraƧao: The LWG changed the PR editorially to specify "neither...nor...meet..." as clearer than "both...and...do not meet...". Change believed to be so minor as not to require re-review. ]

Date: 2010-10-21.18:28:33

[ Redmond: the original proposed resolution didn't impose an explicit requirement that the iterator's value type must be copy constructible, on the grounds that an input iterator's value type must always be copy constructible. Not everyone in the LWG thought that this requirement was clear from table 72. It has been suggested that it might be possible to implement unique_copy without requiring assignability, although current implementations do impose that requirement. Howard provided new wording. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

In 25.2.8 change:

-4- Requires: The ranges [first, last) and [result, result+(last-first)) shall not overlap.

to:

-4- Requires: The ranges [first, last) and [result, result+(last-first)) shall not overlap. The expression *result = *first must be valid. If neither InputIterator nor OutputIterator meets the requirements of forward iterator then the value type of InputIterator must be copy constructible. Otherwise copy constructible is not required.

Date: 2000-05-15.00:00:00

Some popular implementations of unique_copy() create temporary copies of values in the input sequence, at least if the input iterator is a pointer. Such an implementation is built on the assumption that the value type is CopyConstructible and Assignable.

It is common practice in the standard that algorithms explicitly specify any additional requirements that they impose on any of the types used by the algorithm. An example of an algorithm that creates temporary copies and correctly specifies the additional requirements is accumulate(), [rand.req].

Since the specifications of unique() and unique_copy() do not require CopyConstructible and Assignable of the InputIterator's value type the above mentioned implementations are not standard-compliant. I cannot judge whether this is a defect in the standard or a defect in the implementations.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1978
2010-10-21 18:28:33adminsetmessages: + msg1977
2010-10-21 18:28:33adminsetmessages: + msg1976
2000-05-15 00:00:00admincreate