<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3183: Normative permission to specialize Ranges variable templates</title>
<meta property="og:title" content="Issue 3183: Normative permission to specialize Ranges variable templates">
<meta property="og:description" content="C++ library issue. Status: C++20">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3183.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="3183"><a href="lwg-defects.html#3183">3183</a>. Normative permission to specialize Ranges variable templates</h3>
<p><b>Section:</b> 24.3.4.8 <a href="https://wg21.link/iterator.concept.sizedsentinel">[iterator.concept.sizedsentinel]</a> <b>Status:</b> <a href="lwg-active.html#C++20">C++20</a>
 <b>Submitter:</b> Casey Carter <b>Opened:</b> 2019-01-14 <b>Last modified:</b> 2021-02-25</p>
<p><b>Priority: </b>0
</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>
<a href="https://wg21.link/p0896r4">P0896R4 "The One Ranges Proposal"</a> added
boolean variable templates <code>std::disable_sized_sentinel</code> and
<code>std::ranges::disable_sized_range</code> which users are intended to specialize
to <code>false</code> for program-defined <code>Iterator</code>-<code>Sentinel</code> pairs
/ <code>Range</code> types which meet the syntax but do not model
the semantics of the <code>SizedSentinel</code> / <code>SizedRange</code> concepts,
respectively. Specializing these traits allows the use of such types with the
library which would otherwise treat them as if they model <code>SizedSentinel</code>
/ <code>SizedRange</code>. The wording in P0896R4 failed, however, to provide
normative permission to specialize these variable templates as is required by
16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> after the application of
<a href="https://wg21.link/p0551r3">P0551R3</a>.
</p><p>
Furthermore, 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a> notably does not require that
program-defined specializations of standard library variable templates meet the
requirements on the primary template (as is the case for class templates) or
indeed any requirements. P0896R4 also added the <code>enable_view</code> variable
template which is used to explicitly opt in or out of the <code>View</code> concept
25.4.5 <a href="https://wg21.link/range.view">[range.view]</a> when the default chosen by the heuristic is
incorrect. P0896R4 did include normative permission to specialize
<code>enable_view</code>, but the wording does not place sufficient requirements on
such user specializations so as to make them usable by the <code>View</code> concept
definition. Specializations must be required to be usable as constant
expressions of type <code>bool</code> to avoid hard errors in the concept.
</p>

<p><i>[2019-02-03 Priority to 0 and Status to Tentatively Ready after five positive votes on the reflector.]</i></p>



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

<blockquote class="note">
<p>
[<i>Drafting Note:</i> This wording uses the recently-defined core language term
"usable in constant expressions" from 7.7 <a href="https://wg21.link/expr.const">[expr.const]</a> paragraph 3
which may be unfamiliar to reviewers.]
</p>
</blockquote>

<ol>
<li><p>Change 24.3.4.8 <a href="https://wg21.link/iterator.concept.sizedsentinel">[iterator.concept.sizedsentinel]</a> as follows:</p>
<blockquote>
<p>
[&hellip;]
</p><p>
(2.2) &mdash; If <code>−N</code> is representable by
<code>iter_difference_t&lt;I&gt;</code>, then <code>i - s</code> is well-defined and
equals <code>−N</code>.
</p><p>
<ins>-?- Pursuant to 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a>, users may specialize
<code>disable_sized_sentinel</code> for cv-unqualified non-array object types
<code>S</code> and <code>I</code> at least one of which is a program-defined type.
Such specializations shall be usable in constant expressions
(7.7 <a href="https://wg21.link/expr.const">[expr.const]</a>) and have type <code>const bool</code>.</ins>
</p><p>
3 [<i>Note:</i> <code>disable_sized_sentinel</code> allows use of sentinels and
iterators with the library that satisfy but do not in fact model
<code>SizedSentinel</code>.&mdash;<i>end note</i>]
</p><p>
[&hellip;]
</p>
</blockquote>
</li>
<li><p>Add an index entry for <code>disable_sized_sentinel</code> that points to
 [iterator.concepts.sizedsentinel].</p>
</li>
<li><p>Change 25.4.4 <a href="https://wg21.link/range.sized">[range.sized]</a> as follows:</p>
<blockquote>
<p>
[&hellip;]
</p><p>
3 [<i>Note:</i> The complexity requirement for the evaluation of
<code>ranges::size</code> is non-amortized, unlike the case for the complexity of
the evaluations of <code>ranges::begin</code> and <code>ranges::end</code> in the
<code>Range</code> concept.&mdash;<i>end note</i>]
</p><p>
<ins>-?- Pursuant to 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a>, users may specialize
<code>disable_sized_range</code> for cv-unqualified program-defined types.
Such specializations shall be usable in constant expressions
(7.7 <a href="https://wg21.link/expr.const">[expr.const]</a>) and have type <code>const bool</code>.</ins>
</p><p>
4 [<i>Note:</i> <code>disable_sized_range</code> allows use of range types with the
library that satisfy but do not in fact model <code>SizedRange</code>.&mdash;<i>end
note</i>]
</p>
</blockquote>
</li>
<li><p>Add an index entry for <code>disable_sized_range</code> that points to
25.4.4 <a href="https://wg21.link/range.sized">[range.sized]</a>.</p>
</li>
<li><p>Change 25.4.5 <a href="https://wg21.link/range.view">[range.view]</a> as follows:</p>
<blockquote>
<p>
[&hellip;]
</p><p>
5 Pursuant to 16.4.5.2.1 <a href="https://wg21.link/namespace.std">[namespace.std]</a>, users may specialize
<code>enable_view</code> to <code>true</code> for <ins>cv-unqualified
program-defined</ins> types which model <code>View</code>, and <code>false</code> for
types which do not. <ins>Such specializations shall be usable in constant
expressions (7.7 <a href="https://wg21.link/expr.const">[expr.const]</a>) and have type <code>const bool</code>.</ins>
</p>
</blockquote>
</li>
</ol>




</body>
</html>
