<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3549: view_interface is overspecified to derive from view_base</title>
<meta property="og:title" content="Issue 3549: view_interface is overspecified to derive from view_base">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3549.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="3549"><a href="lwg-defects.html#3549">3549</a>. <code>view_interface</code> is overspecified to derive from <code>view_base</code></h3>
<p><b>Section:</b> 25.5.3 <a href="https://wg21.link/view.interface">[view.interface]</a>, 25.4.5 <a href="https://wg21.link/range.view">[range.view]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Tim Song <b>Opened:</b> 2021-05-09 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#view.interface">issues</a> in [view.interface].</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>view_interface&lt;D&gt;</code> is currently specified to publicly derive from
<code>view_base</code>. This derivation requires unnecessary padding in range adaptors
like <code>reverse_view&lt;V&gt;</code>: the <code>view_base</code> subobject of the
<code>reverse_view</code> is required to reside at a different address than the
<code>view_base</code> subobject of <code>V</code> (assuming that <code>V</code> similarly
opted into being a view through derivation from <code>view_interface</code> or
<code>view_base</code>).
<p/>
This appears to be a case of overspecification: we want public and unambiguous
derivation from <code>view_interface</code> to make the class a <code>view</code>; the exact
mechanism of how that opt-in is accomplished should have been left as an
implementation detail.
<p/>
The proposed resolution below has been implemented on top of libstdc++ master
and passes its ranges testsuite, with the exception of a test that checks for the size of
various range adaptors (and therefore asserts the existence of
<code>view_base</code>-induced padding).
</p>

<p><i>[2021-05-17; Reflector poll]</i></p>

<p>
Priority set to 2.
</p>


<p><i>[2021-05-26; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after five votes in favour during reflector poll.
</p>

<p><i>[2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting &rarr; WP.]</i></p>



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

<ol>
<li><p>Modify 25.4.5 <a href="https://wg21.link/range.view">[range.view]</a> as indicated:</p>

<blockquote>
<pre>
<ins>template&lt;class T&gt;
  inline constexpr bool <i>is-derived-from-view-interface</i> = <i>see below</i>;   // exposition only</ins>
template&lt;class T&gt;
  inline constexpr bool enable_view = derived_from&lt;T, view_base&gt; <ins>|| <i>is-derived-from-view-interface</i>&lt;T&gt;</ins>;
</pre>
<blockquote>
<p>
<ins>-?- For a type <code>T</code>, <code><i>is-derived-from-view-interface</i>&lt;T&gt;</code>
is <code>true</code> if and only if <code>T</code> has exactly one public base class
<code>view_interface&lt;U&gt;</code> for some type <code>U</code> and
<code>T</code> has no base classes of type <code>view_interface&lt;V&gt;</code> for any
other type <code>V</code>.</ins>
<p/>
-5- Remarks: 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 cv-unqualified program-defined types which
model <code>view</code>, and <code>false</code> for types which do not. 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>.
</p>
</blockquote>
</blockquote>

</li>
<li>
<p>Modify 25.5.3.1 <a href="https://wg21.link/view.interface.general">[view.interface.general]</a> as indicated: </p>
<blockquote>
<pre>
namespace std::ranges {
  template&lt;class D&gt;
    requires is_class_v&lt;D&gt; &amp;&amp; same_as&lt;D, remove_cv_t&lt;D&gt;&gt;
  class view_interface <del>: public view_base</del> {

  [&hellip;]

  };
}
</pre>
</blockquote>
</li>
</ol>





</body>
</html>
