<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1079: UK-265: RandomAccessIterator's operator- has nonsensical effects clause</title>
<meta property="og:title" content="Issue 1079: UK-265: RandomAccessIterator's operator- has nonsensical effects clause">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1079.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++11">C++11</a> status.</em></p>
<h3 id="1079"><a href="lwg-defects.html#1079">1079</a>. UK-265: <code>RandomAccessIterator</code>'s <code>operator-</code> has nonsensical effects clause</h3>
<p><b>Section:</b> 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Doug Gregor <b>Opened:</b> 2009-03-20 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#random.access.iterators">issues</a> in [random.access.iterators].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses UK 265</b></p>

<p>UK-265:</p>
<p>
This effects clause is nonesense. It looks more like an axiom stating
equivalence, and certainly an effects clause cannot change the state of
two arguments passed by const reference
</p>

<p><i>[
2009-09-18 Alisdair adds:
]</i></p>


<blockquote>
<p>
For random access iterators, the definitions of <code>(b-a)</code> and
<code>(a&lt;b)</code> are circular:
</p>

<p>
From table Table 104 -- Random access iterator requirements:
</p>

<blockquote><pre>
b - a :==&gt;  (a &lt; b) ? distance(a,b) : -distance(b,a)

a &lt; b :==&gt;  b - a &gt; 0
</pre></blockquote>
</blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Moved to Ready.
</p></blockquote>

<p><i>[
2010-02-13 Alisdair opens.
]</i></p>


<blockquote>
<p>
Looking again at LWG <a href="lwg-defects.html#1079" title="UK-265: RandomAccessIterator's operator- has nonsensical effects clause (Status: C++11)">1079</a><sup><a href="https://cplusplus.github.io/LWG/issue1079" title="Latest snapshot">(i)</a></sup>, the wording in the issue no longer exists, and
appears to be entirely an artefact of the concepts wording.
</p>

<p>
This issue is currently on our Ready list (not even Tentative!) but I think it
has to be pulled as there is no way to apply the resolution.
</p>

<p>
Looking at the current paper, I think this issue is now "NAD, solved by the
removal of concepts".  Unfortunately it is too late to poll again, so we will
have to perform that review in Pittsburgh.
</p>
</blockquote>

<p><i>[
2010-02-13 Daniel updates the wording to address the circularity problem.
]</i></p>


<blockquote>
<p><i>[
The previous wording is preserved here:
]</i></p>

<blockquote>

<p>Modify 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>p7-9 as follows:</p>

<blockquote><pre>
difference_type operator-(const X&amp; a, const X&amp; b);
</pre>
<blockquote><p>
  -7- <i>Precondition</i>: there exists a value <code>n</code> of
  <code>difference_type</code> such that <code>a == b + n</code>.
  <p/>
  -8- <del><i>Effects</i>: <code>b == a + (b - a)</code></del>
  <p/>
  -9- <i>Returns</i>: <del><code>(a &lt; b) ? distance(a,b) :
  -distance(b,a)</code></del><ins><code>n</code></ins>
</p></blockquote>
</blockquote>

</blockquote>
</blockquote>

<p><i>[
2010 Pittsburgh:
]</i></p>


<blockquote><p>
Moved to Ready for Pittsburgh.
</p></blockquote>



<p id="res-1079"><b>Proposed resolution:</b></p>
<p>
Modify Table 105 in 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>:
</p>

<blockquote>
<table border="1">
<caption>Table 105 &mdash; Random access iterator requirements (in addition to
bidirectional iterator)</caption>

<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational semantics</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
</tr>

<tr>
<td><code>b - a</code></td>
<td><code>Distance</code></td>
<td><code><del>distance(a,b)</del></code>
<ins>return <code>n</code></ins></td>
<td>pre: there exists a value <code>n</code> of <code>Distance</code> such that <code>a +
n == b</code>. <code>b == a + (b - a)</code>.</td>
</tr>

</table>
</blockquote>





</body>
</html>
