<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3403: Domain of ranges::ssize(E) doesn't match ranges::size(E)</title>
<meta property="og:title" content="Issue 3403: Domain of ranges::ssize(E) doesn't match ranges::size(E)">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3403.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="3403"><a href="lwg-defects.html#3403">3403</a>. Domain of <code>ranges::ssize(E)</code> doesn't match <code>ranges::size(E)</code></h3>
<p><b>Section:</b> 25.3.11 <a href="https://wg21.link/range.prim.ssize">[range.prim.ssize]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2020-02-19 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</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>
<code>ranges::size(E)</code> works with a non-range for which <code>E.size()</code> or <code>size(E)</code> is valid.
But <code>ranges::ssize(E)</code> requires the type <code>range_difference_t</code> which requires
<code>ranges::begin(E)</code> to be valid. This means there are types for which <code>ranges::size(E)</code>
is valid but <code>ranges::ssize(E)</code> is not.
<p/>
Casey's reaction to this is:
<p/>
I believe we want <code>ranges::ssize</code> to work with any argument that <code>ranges::size</code> accepts.
That suggest to me that we're going to need <code><i>make-signed-like-t</i>&lt;T&gt;</code> after all,
so we can "Let <code>E</code> be an expression, and let <code>D</code> be the wider of <code>ptrdiff_t</code>
or <code>decltype(ranges::size(E))</code>. Then <code>ranges::ssize(E)</code> is expression-equivalent to
<code>static_cast&lt;<i>make-signed-like-t</i>&lt;D&gt;&gt;(ranges::size(E))</code>." Although this wording
is still slightly icky since <code>D</code> isn't a valid type when <code>ranges::size(E)</code> isn't a valid
expression, I think it's an improvement?
</p>

<p><i>[2020-03-11 Issue Prioritization]</i></p>

<p>Priority to 2 after reflector discussion.</p>

<p><i>[2020-07-22 Casey provides wording]</i></p>


<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/n4861">N4861</a>.
</p>

<ol>
<li><p>Add a new paragraph after paragraph 1 in 25.2 <a href="https://wg21.link/ranges.syn">[ranges.syn]</a>:</p>
<blockquote>
<ins>
-?- Also within this clause,
<code><i>make-signed-like-t</i>&lt;X&gt;</code>
for an integer-like type <code>X</code>
denotes <code>make_signed_t&lt;X&gt;</code>
if <code>X</code> is an integer type;
otherwise, it denotes a corresponding
unspecified signed-integer-like type
of the same width as <code>X</code>.
</ins>
</blockquote>
</li>

<li><p>Modify 25.3.11 <a href="https://wg21.link/range.prim.ssize">[range.prim.ssize]</a> as indicated:</p>

<blockquote>
<p>-1- The name <code>ranges::ssize</code> denotes
a customization point object (16.3.3.3.5 <a href="https://wg21.link/customization.point.object">[customization.point.object]</a>).
<del>The expression <code>ranges::ssize(E)</code>
for a subexpression <code>E</code> of type <code>T</code>
is expression-equivalent to:</del>
</p><p>
<del>(1.1) &mdash; If <code>range_difference_t&lt;T&gt;</code> has
width less than <code>ptrdiff_t</code>,
<code>static_cast&lt;ptrdiff_t&gt;(ranges::size(E))</code>.</del>
</p><p>
<del>(1.2) &mdash; Otherwise,
<code>static_cast&lt;range_difference_t&lt;T&gt;&gt;(ranges::size(E))</code>.</del>
</p><p>
<ins>
-?- Given a subexpression <code>E</code> with type <code>T</code>,
let <code>t</code> be an lvalue that denotes the reified object for <code>E</code>.
If <code>ranges::size(t)</code> is ill-formed,
<code>ranges::ssize(E)</code> is ill-formed.
Otherwise, let <code>D</code> be the wider of
<code>ptrdiff_t</code> or <code>decltype(ranges::size(t))</code>;
<code>ranges::ssize(E)</code> is expression-equivalent to
<code>static_cast&lt;<i>make-signed-like-t</i>&lt;D&gt;&gt;(ranges::size(t))</code>.
</ins>
</p>
</blockquote>
</li>
</ol>
</blockquote>

<p><i>[2020-07-31 Casey provides updated wording]</i></p>

Per discussion on the reflector.

<p><i>[2020-08-21; Issue processing telecon: Tentatively Ready]</i></p>

<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready &rarr; WP.]</i></p>



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

<ol>
<li><p>Add a new paragraph after paragraph 1 in 25.2 <a href="https://wg21.link/ranges.syn">[ranges.syn]</a>:</p>
<blockquote class="note">
<p>
[<i>Drafting note:</i> The following does not define
an analog <code><i>to-signed-like</i></code> for <code><i>to-unsigned-like</i></code>
since we don't need it at this time.]
</p>
</blockquote>
<blockquote>
<ins>
-?- Also within this Clause,
<code><i>make-signed-like-t</i>&lt;X&gt;</code>
for an integer-like type <code>X</code>
denotes <code>make_signed_t&lt;X&gt;</code>
if <code>X</code> is an integer type;
otherwise, it denotes a corresponding
unspecified signed-integer-like type
of the same width as <code>X</code>.
</ins>
</blockquote>
</li>

<li><p>Modify 25.3.11 <a href="https://wg21.link/range.prim.ssize">[range.prim.ssize]</a> as indicated:</p>

<blockquote>
<p>-1- The name <code>ranges::ssize</code> denotes
a customization point object (16.3.3.3.5 <a href="https://wg21.link/customization.point.object">[customization.point.object]</a>).
<del>The expression <code>ranges::ssize(E)</code>
for a subexpression <code>E</code> of type <code>T</code>
is expression-equivalent to:</del>
</p><p>
<del>(1.1) &mdash; If <code>range_difference_t&lt;T&gt;</code> has
width less than <code>ptrdiff_t</code>,
<code>static_cast&lt;ptrdiff_t&gt;(ranges::size(E))</code>.</del>
</p><p>
<del>(1.2) &mdash; Otherwise,
<code>static_cast&lt;range_difference_t&lt;T&gt;&gt;(ranges::size(E))</code>.</del>
</p><p>
<ins>
-?- Given a subexpression <code>E</code> with type <code>T</code>,
let <code>t</code> be an lvalue that denotes the reified object for <code>E</code>.
If <code>ranges::size(t)</code> is ill-formed,
<code>ranges::ssize(E)</code> is ill-formed.
Otherwise let <code>D</code> be
<code><i>make-signed-like-t</i>&lt;decltype(ranges::size(t))&gt;</code>,
or <code>ptrdiff_t</code> if it is wider than that type;
<code>ranges::ssize(E)</code> is expression-equivalent to
<code>static_cast&lt;D&gt;(ranges::size(t))</code>.
</ins>
</p>
</blockquote>
</li>
</ol>




</body>
</html>
