<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2589: match_results can't satisfy the requirements of a container</title>
<meta property="og:title" content="Issue 2589: match_results can't satisfy the requirements of a container">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2589.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#C++17">C++17</a> status.</em></p>
<h3 id="2589"><a href="lwg-defects.html#2589">2589</a>. <code>match_results</code> can't satisfy the requirements of a container</h3>
<p><b>Section:</b> 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> S. B. Tam <b>Opened:</b> 2016-01-24 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#re.results">issues</a> in [re.results].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
N4567 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> p2 mentions
</p>
<blockquote>
<p>
The class template <code>match_results</code> shall satisfy the requirements of an allocator-aware container and of a
sequence container, as specifed in 23.2.3, except that only operations defined for const-qualified sequence
containers are supported.
</p>
</blockquote>
<p>
However, this is impossible because <code>match_results</code> has a <code>operator==</code> whose semantics differs from the one 
required in Table 95 &mdash; "Container requirements".
<p/>
Table 95 requires that <code>a == b</code> is an equivalence relation and means <code>equal(a.begin(), a.end(), b.begin(), b.end())</code>. 
But for <code>match_results</code>, <code>a == b</code> and <code>equal(a.begin(), a.end(), b.begin(), b.end())</code> can give different 
results. For example:
</p>
<blockquote><pre>
#include &lt;iostream&gt;
#include &lt;regex&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

int main()
{
  std::regex re("a*");
  std::string target("baaab");
  std::smatch a;

  std::regex_search(target, a, re);

  std::string target2("raaau");
  std::smatch b;

  std::regex_search(target2, b, re);

  std::cout &lt;&lt; std::boolalpha;
  std::cout &lt;&lt; (a == b) &lt;&lt; '\n'; // false
  std::cout &lt;&lt; std::equal(a.begin(), a.end(), b.begin(), b.end()) &lt;&lt; '\n'; // true
}
</pre></blockquote>
<p><i>[2016-02, Issues Telecon]</i></p>

Marshall: The submitter is absolutely right, but the proposed resolution is insufficient. We should avoid "shall", for once.<br/>
Jonathan: This is NAD, because the container comparison functions say "unless otherwise stated", 23.3.1p14 and table 97.<br/>
Ville: wrong, table 95 is relevant for ==.<br/>
Jonathan: good point<br/>

<p>2016-05: Marshall cleans up the wording around the change</p>

<p><i>[2016-08 - Chicago]</i></p>

<p>Thurs AM: Moved to Tentatively Ready</p>

<p>
<strong>Previous resolution [SUPERSEDED]:</strong>
</p>
<blockquote class="note">
<p>
This wording is relative to N4567.
</p>

<ol>
<li><p>Change 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> p2 as indicated:</p>
<blockquote><p>
-2- The class template <code>match_results</code> shall satisfy the requirements of an allocator-aware container and of a
sequence container, as specified in 23.2.3, except that only operations defined for const-qualified sequence
containers are supported <ins>and that the semantics of comparison functions are different from those required for a 
container</ins>.
</p></blockquote>
</li>
</ol>
</blockquote>



<p id="res-2589"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4567.
</p>

<ol>
<li><p>Change 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> p2 as indicated:</p>
<blockquote><p>
-2- The class template <code>match_results</code> <del>shall satisfy</del><ins>satisfies</ins> the requirements of an allocator-aware container and of a
sequence container, <del>as specified in </del><ins>(</ins>23.2.3<ins>)</ins>, except that only operations defined for const-qualified sequence
containers are supported <ins>and the semantics of comparison functions are different from those required for a 
container</ins>.
</p></blockquote>
</li>
</ol>

<blockquote class="note">
<p>
[<i>Drafting note:</i> (Post-Issaquah) Due to the outdated N4567 wording the project editor accepted the following merge 
suggestion into N4606 wording: &mdash; <i>end drafting note</i>]
</p>
<blockquote>
<p>
This wording is relative to N4606.
</p>

<ol>
<li><p>Change 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> p2 as indicated:</p>
<blockquote><p>
-2- The class template <code>match_results</code> satisfies the requirements of an
allocator-aware container and of a sequence container, <del>as specified in</del> 
<ins>(</ins>23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a><del> and</del><ins>,</ins> 
23.2.4 <a href="https://wg21.link/sequence.reqmts">[sequence.reqmts]</a><ins>)</ins><del> respectively</del>, except that only 
operations defined for const-qualified sequence containers are supported <ins>and the 
semantics of comparison functions are different from those required for a container</ins>.
</p></blockquote>
</li>
</ol>

</blockquote>
</blockquote>





</body>
</html>
