Title
Under-specification of operator== for regex_token_iterator
Status
open
Section
[re.tokiter.comp]
Submitter
Pete Becker

Created on 2012-11-21.00:00:00 last changed 69 months ago

Messages

Date: 2018-08-23.14:35:23

Proposed resolution:

This wording is relative to N4762.

  • Modify [re.tokiter.comp] as follows:

    bool operator==(const regex_token_iterator& right) const;
    

    -?- Expects: At least one of *this and right is an end-of-sequence iterator, or both *this and right have the same underlying sequence.

    -1- Returns: true if *this and right are both end-of-sequence iterators, or if […]

    bool operator!=(const regex_token_iterator& right) const;
    

    -?- Expects: At least one of *this and right is an end-of-sequence iterator, or both *this and right have the same underlying sequence.

    -2- Returns: !(*this == right).

Date: 2018-08-23.00:00:00

[ 2018-08-23 Casey revises the P/R in response to LWG feedback ]

Date: 2018-08-20.00:00:00

[ 2018-08-20 Casey adds a proposed resolution ]

Priority changed to 3.

Marshall notes that iterator comparisons typically require the iterators to denote elements of the same sequence.

Previous resolution [SUPERSEDED]:

This wording is relative to N4762.

  • Modify [re.tokiter.comp] as follows:

    bool operator==(const regex_token_iterator& right) const;
    

    -?- Expects: *this and right are both end-of-sequence iterators or both have the same underlying sequence.

    -1- Returns: true if *this and right are both end-of-sequence iterators, or if […]

    bool operator!=(const regex_token_iterator& right) const;
    

    -?- Expects: *this and right are both end-of-sequence iterators or both have the same underlying sequence.

    -2- Returns: !(*this == right).

Date: 2014-02-10.00:00:00

[ 2014-02-10 ]

Priority set to 2

Date: 2012-11-21.00:00:00

Consider the following example:

std::string str0("x");
std::regex rg0("a");
std::regex_token_iterator it0(str0.begin(), str0.end(), rg0, -1); // points at "x" in str0
std::string str1("x");
std::regex rg1("b");
std::regex_token_iterator it1(str1.begin(), str1.end(), rg1, -1); // points at "x" in str1

[re.tokiter.comp] p1 says that it0.operator==(it1) returns true "if *this and right are both suffix iterators and suffix == right.suffix"; both conditions are satisfied in this example. It does not say that they must both be iterators into the same sequence, nor does it say (as general iterator requirements do) that they must both be in the domain of == in order for the comparison to be meaningful. It's a simple statement: they're equal if the strings they point at compare equal. Given this being a valid comparison, the obtained result of "true" looks odd.

The problem is that for iterator values prior to the suffix iterator, equality means the same regular expression and the same matched sequence (both uses of "same" refer to identity, not equality); for the suffix iterator, equality means that the matched sequences compare equal.

History
Date User Action Args
2018-08-23 14:35:23adminsetmessages: + msg10106
2018-08-22 12:55:05adminsetstatus: new -> open
2018-08-20 17:43:23adminsetmessages: + msg10087
2018-08-20 17:43:23adminsetmessages: + msg10086
2018-01-22 19:10:31adminsetmessages: + msg9618
2012-11-21 00:00:00admincreate