<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2220: Under-specification of operator== for regex_token_iterator</title>
<meta property="og:title" content="Issue 2220: Under-specification of operator== for regex_token_iterator">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2220.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Open">Open</a> status.</em></p>
<h3 id="2220"><a href="lwg-active.html#2220">2220</a>. Under-specification of <code>operator==</code> for <code>regex_token_iterator</code></h3>
<p><b>Section:</b> 28.6.11.2.3 <a href="https://wg21.link/re.tokiter.comp">[re.tokiter.comp]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Pete Becker <b>Opened:</b> 2012-11-21 <b>Last modified:</b> 2024-10-03</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>

<p>
Consider the following example:
</p>
<blockquote><pre>
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
</pre></blockquote>
<p>
28.6.11.2.3 <a href="https://wg21.link/re.tokiter.comp">[re.tokiter.comp]</a> p1 says that <code>it0.operator==(it1)</code> returns true "if
<code>*this</code> and <code>right</code> are both suffix iterators and <code>suffix == right.suffix</code>"; 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 <code>==</code> 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.
<p/>
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.
</p>

<p><i>[2014-02-10]</i></p>

<p>Priority set to 2</p>

<p><i>[2018-08-20 Casey adds a proposed resolution]</i></p>

<p>Priority changed to 3.</p>
Marshall notes that iterator comparisons typically require the iterators to
denote elements of the same sequence.

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>This wording is relative to <a href="https://wg21.link/n4762">N4762</a>.</p>

<ul>
<li><p>Modify 28.6.11.2.3 <a href="https://wg21.link/re.tokiter.comp">[re.tokiter.comp]</a> as follows:</p>
<blockquote>
<pre>
bool operator==(const regex_token_iterator&amp; right) const;
</pre>
<p>
<ins>-?- <i>Expects:</i> <code>*this</code> and <code>right</code> are both
end-of-sequence iterators or both have the same underlying sequence.</ins>
</p><p>
-1- <i>Returns:</i> <code>true</code> if <code>*this</code> and <code>right</code> are both
end-of-sequence iterators, or if [&hellip;]
</p>
<pre>
bool operator!=(const regex_token_iterator&amp; right) const;
</pre>
<p>
<ins>-?- <i>Expects:</i> <code>*this</code> and <code>right</code> are both
end-of-sequence iterators or both have the same underlying sequence.</ins>
</p><p>
-2- <i>Returns:</i> <code>!(*this == right)</code>.
</p>
</blockquote>
</li>
</ul>
</blockquote>

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


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<p>This wording is relative to <a href="https://wg21.link/n4762">N4762</a>.</p>

<ul>
<li><p>Modify 28.6.11.2.3 <a href="https://wg21.link/re.tokiter.comp">[re.tokiter.comp]</a> as follows:</p>
<blockquote>
<pre>
bool operator==(const regex_token_iterator&amp; right) const;
</pre>
<p>
<ins>-?- <i>Expects:</i> At least one of <code>*this</code> and <code>right</code> is an
end-of-sequence iterator, or both <code>*this</code> and <code>right</code> have the
same underlying sequence.</ins>
</p><p>
-1- <i>Returns:</i> <code>true</code> if <code>*this</code> and <code>right</code> are both
end-of-sequence iterators, or if [&hellip;]
</p>
<pre>
bool operator!=(const regex_token_iterator&amp; right) const;
</pre>
<p>
<ins>-?- <i>Expects:</i> At least one of <code>*this</code> and <code>right</code> is an
end-of-sequence iterator, or both <code>*this</code> and <code>right</code> have the
same underlying sequence.</ins>
</p><p>
-2- <i>Returns:</i> <code>!(*this == right)</code>.
</p>
</blockquote>
</li>
</ul>
</blockquote>

<p><i>[2024-10-03; Jonathan rebases the wording on the latest WP]</i></p>




<p id="res-2220"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/N4988" title=" Working Draft, Programming Languages — C++">N4988</a>.</p>

<ul>
<li><p>Modify 28.6.11.2.3 <a href="https://wg21.link/re.tokiter.comp">[re.tokiter.comp]</a> as follows:</p>
<blockquote>
<pre>
bool operator==(const regex_token_iterator&amp; right) const;
</pre>
<p>
<ins>-?- <i>Preconditions:</i>
At least one of <code>*this</code> and <code>right</code> is an end-of-sequence iterator,
or <code>*this</code> and <code>right</code> have the same underlying sequence.</ins>
</p><p>
-1- <i>Returns:</i> <code>true</code> if <code>*this</code> and <code>right</code> are both
end-of-sequence iterators,
or if <code class='backtick'>*this</code> and <code class='backtick'>right</code> are both suffix iterators and <code class='backtick'>suffix == right.suffix</code>;
otherwise returns <code class='backtick'>false</code> if <code class='backtick'>*this</code> or <code class='backtick'>right</code> is an end-of-sequence iterator
or a suffix iterator.
Otherwise returns <code class='backtick'>true</code> if <code class='backtick'>position == right.position</code>, <code class='backtick'>N == right.N</code>,
and <code class='backtick'>subs == right.subs</code>.
Otherwise returns <code class='backtick'>false</code>.
</p>
</blockquote>
</li>
</ul>






</body>
</html>
