This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Open status.
operator==
for regex_token_iterator
Section: 28.6.11.2.3 [re.tokiter.comp] Status: Open Submitter: Pete Becker Opened: 2012-11-21 Last modified: 2024-10-03
Priority: 3
View all issues with Open status.
Discussion:
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
28.6.11.2.3 [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.
[2014-02-10]
Priority set to 2
[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 28.6.11.2.3 [re.tokiter.comp] as follows:
bool operator==(const regex_token_iterator& right) const;-?- Expects:
*this
andright
are both end-of-sequence iterators or both have the same underlying sequence.-1- Returns:
true
if*this
andright
are both end-of-sequence iterators, or if […]bool operator!=(const regex_token_iterator& right) const;-?- Expects:
*this
andright
are both end-of-sequence iterators or both have the same underlying sequence.-2- Returns:
!(*this == right)
.
[2018-08-23 Casey revises the P/R in response to LWG feedback]
Previous resolution [SUPERSEDED]:
This wording is relative to N4762.
Modify 28.6.11.2.3 [re.tokiter.comp] as follows:
bool operator==(const regex_token_iterator& right) const;-?- Expects: At least one of
*this
andright
is an end-of-sequence iterator, or both*this
andright
have the same underlying sequence.-1- Returns:
true
if*this
andright
are both end-of-sequence iterators, or if […]bool operator!=(const regex_token_iterator& right) const;-?- Expects: At least one of
*this
andright
is an end-of-sequence iterator, or both*this
andright
have the same underlying sequence.-2- Returns:
!(*this == right)
.
[2024-10-03; Jonathan rebases the wording on the latest WP]
Proposed resolution:
This wording is relative to N4988.
Modify 28.6.11.2.3 [re.tokiter.comp] as follows:
bool operator==(const regex_token_iterator& right) const;-?- Preconditions: At least one of
*this
andright
is an end-of-sequence iterator, or*this
andright
have the same underlying sequence.-1- Returns:
true
if*this
andright
are both end-of-sequence iterators, or if*this
andright
are both suffix iterators andsuffix == right.suffix
; otherwise returnsfalse
if*this
orright
is an end-of-sequence iterator or a suffix iterator. Otherwise returnstrue
ifposition == right.position
,N == right.N
, andsubs == right.subs
. Otherwise returnsfalse
.