<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2306: match_results::reference should be value_type&amp;, not const value_type&amp;</title>
<meta property="og:title" content="Issue 2306: match_results::reference should be value_type&amp;, not const value_type&amp;">
<meta property="og:description" content="C++ library issue. Status: C++14">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2306.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++14">C++14</a> status.</em></p>
<h3 id="2306"><a href="lwg-defects.html#2306">2306</a>. <code>match_results::reference</code> should be <code>value_type&amp;</code>, not <code>const value_type&amp;</code></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++14">C++14</a>
 <b>Submitter:</b> Matt Austern <b>Opened:</b> 2013-09-25 <b>Last modified:</b> 2017-07-05</p>
<p><b>Priority: </b>4
</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++14">C++14</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The match_results class synopsis has
</p>
<blockquote><pre>
typedef const value_type&amp; const_reference;
typedef const_reference reference;
</pre></blockquote>
<p>
We're getting too enthusiastic about types here by insisting that <code>reference</code> is a const reference, even 
though <code>match_results</code> is a read-only container. In the container requirements table (Table 96, in section 
23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> we say that <code>Container::reference</code> is "lvalue of <code>T</code>" and 
<code>Container::const_reference</code> is "const lvalue of <code>T</code>".
</p>
<p>
That phrasing in the container requirements table is admittedly a little fuzzy and ought to be clarified (as discussed in 
lwg issue <a href="lwg-defects.html#2182" title="Container::[const_]reference types are misleadingly specified (Status: C++14)">2182</a><sup><a href="https://cplusplus.github.io/LWG/issue2182" title="Latest snapshot">(i)</a></sup>), but in context it's clear that <code>Container::reference</code> ought to be a <code>T&amp;</code> 
even for constant containers. In the rest of Clause 23 we see that <code>Container::reference</code> is <code>T&amp;</code>, not 
<code>const T&amp;</code>, even for const-qualified containers and that it's <code>T&amp;</code>, not <code>const T&amp;</code>, even 
for containers like <code>set</code> and <code>unordered_set</code> that provide const iterators only.
<p/>
The way we handle const containers is just that in the case of a const-qualified container (including <code>match_results</code>) 
there are no operations that return <code>Container::reference</code>. That's already the case, so this issue is complaining 
about an unused typedef.
</p>

<p><i>[2013-10-17: Daniel comments]</i></p>

<p>
The <code>std::initializer_list</code> synopsis, 17.11 <a href="https://wg21.link/support.initlist">[support.initlist]</a> shows a similar problem:
</p>
<blockquote><pre>
template&lt;class E&gt; class initializer_list {
public:
  typedef E value_type;
  typedef const E&amp; reference;
  typedef const E&amp; const_reference;
  [&hellip;]
}
</pre></blockquote>
<p>
Given the fact that <code>std::initializer_list</code> doesn't meet the container requirements anyway (and is such a core-language related
type) I recommend to stick with the current state.
</p>

<p><i>[Issaquah 2014-02-11: Move to Immediate]</i></p>




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

<ol>
<li><p>Change the class template <code>match_results</code> header synopsis, 28.6.9 <a href="https://wg21.link/re.results">[re.results]</a> p4 as indicated:</p>

<blockquote><pre>
typedef const value_type&amp; const_reference;
typedef <del>const_reference</del><ins>value_type&amp;</ins> reference;
</pre></blockquote>
</li>
</ol>





</body>
</html>
