Skip to content

[forwardlist.ops] bogus specification of forward_list::unique LWG2997 #4221

Closed
@zygoloid

Description

@zygoloid

The specification for forward_list::unique says:

Erases all but the first element from every consecutive group of equal elements referred to by the iterator i in the range [first + 1, last) for which *i == *(i-1) (for the version with no arguments) or pred(*i, *(i - 1)) (for the version with a predicate argument) holds.

Err, what?

Given {1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, we:

  1. consider the range [first + 1, last): {1, 1, 1, 1, 2, 2, 2, 2, 2}.
  2. identify the elements for which *i == *(i-1), dropping the first 2.
  3. identify the consecutive groups of equal elements from step (2): {1, 1, 1, 1} and {2, 2, 2, 2}.
  4. erase all but the first element from each such group.

The result is {1, 1, 2, 2}. That doesn't seem right.

The problem here is that we express basically every part of the rules twice or three times in the same sentence, and usually at least all but one of those repetitions is wrong. (Eg, compare "equal" to the more careful description later, compare "all but the first" with the use of [first + 1, last) and *i == *(i-1).)

Perhaps we meant:

Erases all but the first element from every consecutive group of equal elements. That is, for a nonempty list, erases all elements referred to by the iterator i in the range [first + 1, last) for which *i == *(i-1) (for the version with no arguments) or pred(*i, *(i - 1)) (for the version with a predicate argument) holds.

Oh, and while we're here: what are first and last supposed to be here? I think it means begin() and end()...

Metadata

Metadata

Assignees

Labels

lwgIssue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions