<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3299: Pointers don't need customized iterator behavior</title>
<meta property="og:title" content="Issue 3299: Pointers don't need customized iterator behavior">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3299.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++20">C++20</a> status.</em></p>
<h3 id="3299"><a href="lwg-defects.html#3299">3299</a>. Pointers don't need customized iterator behavior</h3>
<p><b>Section:</b> 24.3.3.1 <a href="https://wg21.link/iterator.cust.move">[iterator.cust.move]</a>, 24.3.3.2 <a href="https://wg21.link/iterator.cust.swap">[iterator.cust.swap]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2019-10-07 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</p>
<p><b>View all other</b> <a href="lwg-index.html#iterator.cust.move">issues</a> in [iterator.cust.move].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++20">C++20</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It is not intentional design that users may customize the behavior of
<code>ranges::iter_move</code> (24.3.3.1 <a href="https://wg21.link/iterator.cust.move">[iterator.cust.move]</a>) and
<code>ranges::iter_swap</code> (24.3.3.2 <a href="https://wg21.link/iterator.cust.swap">[iterator.cust.swap]</a>)  for pointers to program-defined
type by defining e.g. <code>iter_move(my_type*)</code> or <code>iter_swap(my_type*, my_type*)</code> in a
namespace associated with <code>my_type</code>. The intent of customization points is that users may
define behavior for types they define, not that users may mess with the well-defined semantics for
existing types like pointers.
</p><p>
We should forbid such silliness by constraining the "finds an overload via ADL" cases for
customization points to only trigger with argument expressions of class or enumeration type. Note
that WG21 made a similar change to <code>ranges::swap</code> shortly before merging it into the working
draft to forbid users customizing behavior for pointers to program-defined types or arrays of
program-defined types.
</p>

<p><i>[2019-11-16 Issue Prioritization]</i></p>

<p>Status to Tentatively Ready and priority to 0 after seven positive votes on the reflector.</p>


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

<blockquote class="note"><p>
[<i>Drafting note:</i> <a href="lwg-defects.html#3247" title="ranges::iter_move should perform ADL-only lookup of iter_move (Status: C++20)">3247</a><sup><a href="https://cplusplus.github.io/LWG/issue3247" title="Latest snapshot">(i)</a></sup> touches the same wording in
24.3.3.1 <a href="https://wg21.link/iterator.cust.move">[iterator.cust.move]</a>; if both are resolved simultaneously the changes should be
reconciled before passing them on to the Editor.]
</p></blockquote>

<ol>
<li><p>Modify 24.3.3.1 <a href="https://wg21.link/iterator.cust.move">[iterator.cust.move]</a> as follows:</p>

<blockquote><p>
(1.1) &mdash; <code>iter_move(E)</code>, if <del>that expression is valid,</del> <ins><code>E</code> has
class or enumeration type and <code>iter_move(E)</code> is a well-formed expression</ins> with overload
resolution performed in a context that does not include a declaration of <code>ranges::iter_move</code>.
</p></blockquote>
</li>

<li><p>Modify 24.3.3.2 <a href="https://wg21.link/iterator.cust.swap">[iterator.cust.swap]</a> as follows:</p>

<blockquote><p>
(4.1) &mdash; <code>(void)iter_swap(E1, E2)</code>, if <del>that expression is valid,</del> <ins>either
<code>E1</code> or <code>E2</code> has class or enumeration type and <code>iter_swap(E1, E2)</code> is a
well-formed expression</ins> with overload resolution performed in a context that includes the
declaration
<blockquote><pre>
template&lt;class I1, class I2&gt;
void iter_swap(I1, I2) = delete;
</pre></blockquote>
and does not include a declaration of <code>ranges::iter_swap</code>. If the function selected by
overload resolution does not exchange the values denoted by <code>E1</code> and <code>E2</code>, the program
is ill-formed with no diagnostic required.
</p></blockquote>
</li>
</ol>





</body>
</html>
