<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3420: cpp17-iterator should check that the type looks like an iterator first</title>
<meta property="og:title" content="Issue 3420: cpp17-iterator should check that the type looks like an iterator first">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3420.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++23">C++23</a> status.</em></p>
<h3 id="3420"><a href="lwg-defects.html#3420">3420</a>. <code><i>cpp17-iterator</i></code> should check that the type looks like an iterator first</h3>
<p><b>Section:</b> 24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2020-02-29 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#iterator.traits">issues</a> in [iterator.traits].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It is common in pre-C++20 code to rely on SFINAE-friendly <code>iterator_traits</code> 
to rule out non-iterators in template constraints (<code>std::filesystem::path</code> 
is one example in the standard library).
<p/>
C++20 changed <code>iterator_traits</code> to automatically detect its members in
some cases, and this detection can cause constraint recursion. LWG <a href="lwg-defects.html#3244" title="Constraints for Source in &sect;[fs.path.req] insufficiently constrainty (Status: C++20)">3244</a><sup><a href="https://cplusplus.github.io/LWG/issue3244" title="Latest snapshot">(i)</a></sup> 
tries to fix this for <code>path</code> by short-circuiting the check when the source type is 
<code>path</code> itself, but this isn't sufficient:
</p>
<blockquote><pre>
struct Foo 
{
  Foo(const std::filesystem::path&amp;);
};

static_assert(std::copyable&lt;Foo&gt;);
</pre></blockquote>
<p>
Here the copyability determination will ask whether a <code>path</code> can be
constructed from a <code>Foo</code>, which asks whether <code>Foo</code> is an iterator, which
checks whether <code>Foo</code> is <code>copyable</code> [&hellip;].
<p/>
To reduce the risk of constraint recursion, we should change <code><i>cpp17-iterator</i></code> 
so that it does not ask about copyability until the type is known to resemble an iterator.
</p>

<p><i>[2020-04-04 Issue Prioritization]</i></p>
 
<p>
Status set to Tentatively Ready after six positive votes on the reflector.
</p>
<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



<p id="res-3420"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.
</p>

<ol>
<li><p>Modify 24.3.2.3 <a href="https://wg21.link/iterator.traits">[iterator.traits]</a> as indicated:</p>

<blockquote>
<p>
-2- The definitions in this subclause make use of the following exposition-only concepts:
</p>
<blockquote>
<pre>
template&lt;class I&gt;
concept <i>cpp17-iterator</i> =
  <del>copyable&lt;I&gt; &amp;&amp;</del> requires(I i) {
    { *i } -&gt; <i>can-reference</i>;
    { ++i } -&gt; same_as&lt;I&amp;&gt;;
    { *i++ } -&gt; <i>can-reference</i>;
  } <ins>&amp;&amp; copyable&lt;I&gt;</ins>;
  
[&hellip;]
</pre>
</blockquote>
</blockquote>
</li>
</ol>




</body>
</html>
