<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3700: The const begin of the join_view family does not require InnerRng to be a range</title>
<meta property="og:title" content="Issue 3700: The const begin of the join_view family does not require InnerRng to be a range">
<meta property="og:description" content="C++ library issue. Status: Resolved">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3700.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#Resolved">Resolved</a> status.</em></p>
<h3 id="3700"><a href="lwg-defects.html#3700">3700</a>. The <code>const begin</code> of the <code>join_view</code> family does not require <code><i>InnerRng</i></code> to be a range</h3>
<p><b>Section:</b> 25.7.14.2 <a href="https://wg21.link/range.join.view">[range.join.view]</a>, 25.7.15.2 <a href="https://wg21.link/range.join.with.view">[range.join.with.view]</a> <b>Status:</b> <a href="lwg-active.html#Resolved">Resolved</a>
 <b>Submitter:</b> Hewill Kang <b>Opened:</b> 2022-05-17 <b>Last modified:</b> 2023-03-23</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#range.join.view">issues</a> in [range.join.view].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Resolved">Resolved</a> status.</p>
<p><b>Discussion:</b></p>
<p>
This is a follow-up of LWG <a href="lwg-active.html#3599" title="The const overload of lazy_split_view::begin should be constrained by const Pattern (Status: New)">3599</a><sup><a href="https://cplusplus.github.io/LWG/issue3599" title="Latest snapshot">(i)</a></sup>.
</p>
<p>
Currently, the <code>const</code> version of <code>join_view::begin</code> has the following constraints
</p>
<blockquote>
<pre>
constexpr auto begin() const
  requires input_range&lt;const V&gt; &amp;&amp;
           is_reference_v&lt;range_reference_t&lt;const V&gt;&gt;
{ return <i>iterator</i>&lt;true&gt;{*this, ranges::begin(<i>base_</i>)}; }
</pre>
</blockquote>
<p>
which only requires <code><i>InnerRng</i></code> to be a reference type, but in some cases, <code><i>InnerRng</i></code>
may not be a <code>range</code>. <a href="https://godbolt.org/z/P8baTb5ee">Consider</a>
</p>
<blockquote>
<pre>
#include &lt;ranges&gt;

int main() {
  auto r = std::views::iota(0, 5)
         | std::views::split(1);
  auto s = std::views::single(r);
  auto j = s | std::views::join;
  auto f = j.front();
}
</pre>
</blockquote>
<p>
The reference type of <code>single_view</code> is <code>const split_view&amp;</code>, which only has the non-<code>const</code>
version of <code>begin</code>, which will cause <code>view_interface</code>'s <code>const front</code> to be incorrectly
instantiated, making <code>r.front()</code> unnecessarily ill-formed.
</p>
<p>
We should add this check for <code>join_view</code>'s <code>const begin</code>, as well as <code>join_with_view</code>.
</p>


<p><i>[2022-06-21; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">

<p>
This wording is relative to <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>.
</p>

<ol>
<li><p>Modify 25.7.14.2 <a href="https://wg21.link/range.join.view">[range.join.view]</a>, class template <code>join_view</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std::ranges {

  [&hellip;]

  template&lt;input_range V&gt;
    requires view&lt;V&gt; &amp;&amp; input_range&lt;range_reference_t&lt;V&gt;&gt;
  class join_view : public view_interface&lt;join_view&lt;V&gt;&gt; {
  private:
    [&hellip;]
  public:
    [&hellip;]

    constexpr auto begin() {
      [&hellip;]
    }

    constexpr auto begin() const
      requires input_range&lt;const V&gt; &amp;&amp;
                <ins>input_range&lt;range_reference_t&lt;const V&gt;&gt; &amp;&amp;</ins>
                is_reference_v&lt;range_reference_t&lt;const V&gt;&gt;
    { return <i>iterator</i>&lt;true&gt;{*this, ranges::begin(<i>base_</i>)}; }

    constexpr auto end() {
      [&hellip;]
    }

    constexpr auto end() const
      requires input_range&lt;const V&gt; &amp;&amp;
                <ins>input_range&lt;range_reference_t&lt;const V&gt;&gt; &amp;&amp;</ins>
                is_reference_v&lt;range_reference_t&lt;const V&gt;&gt; {
      if constexpr (forward_range&lt;const V&gt; &amp;&amp;
                    forward_range&lt;range_reference_t&lt;const V&gt;&gt; &amp;&amp;
                    common_range&lt;const V&gt; &amp;&amp;
                    common_range&lt;range_reference_t&lt;const V&gt;&gt;)
        return <i>iterator</i>&lt;true&gt;{*this, ranges::end(<i>base_</i>)};
      else
        return <i>sentinel</i>&lt;true&gt;{*this};
    }
  };

  [&hellip;]

}
</pre>
</blockquote>
</li>

<li><p>Modify 25.7.15.2 <a href="https://wg21.link/range.join.with.view">[range.join.with.view]</a>, class template <code>join_with_view</code> synopsis, as indicated:</p>

<blockquote>
<pre>
namespace std::ranges {

  [&hellip;]

  template&lt;input_range V, forward_range Pattern&gt;
  requires view&lt;V&gt; &amp;&amp; input_range&lt;range_reference_t&lt;V&gt;&gt;
        &amp;&amp; view&lt;Pattern&gt;
        &amp;&amp; <i>compatible-joinable-ranges</i>&lt;range_reference_t&lt;V&gt;, Pattern&gt;
  class join_with_view : public view_interface&lt;join_with_view&lt;V, Pattern&gt;&gt; {
  private:
    [&hellip;]
  public:
    [&hellip;]

    constexpr auto begin() {
      [&hellip;]
    }
    constexpr auto begin() const
      requires input_range&lt;const V&gt; &amp;&amp;
                forward_range&lt;const Pattern&gt; &amp;&amp;
                <ins>input_range&lt;range_reference_t&lt;const V&gt;&gt; &amp;&amp;</ins>
                is_reference_v&lt;range_reference_t&lt;const V&gt;&gt; {
      return <i>iterator</i>&lt;true&gt;{*this, ranges::begin(<i>base_</i>)};
    }

    constexpr auto end() {
      [&hellip;]
    }
    constexpr auto end() const
      requires input_range&lt;const V&gt; &amp;&amp; forward_range&lt;const Pattern&gt; &amp;&amp;
                <ins>input_range&lt;range_reference_t&lt;const V&gt;&gt; &amp;&amp;</ins>
                is_reference_v&lt;range_reference_t&lt;const V&gt;&gt; {
      using InnerConstRng = range_reference_t&lt;const V&gt;;
      if constexpr (forward_range&lt;const V&gt; &amp;&amp; forward_range&lt;InnerConstRng&gt; &amp;&amp;
                    common_range&lt;const V&gt; &amp;&amp; common_range&lt;InnerConstRng&gt;)
        return <i>iterator</i>&lt;true&gt;{*this, ranges::end(<i>base_</i>)};
      else
        return <i>sentinel</i>&lt;true&gt;{*this};
    }
  };

  [&hellip;]

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

<p><i>[2023-03-22 Resolved by the adoption of <a href="https://wg21.link/P2770R0" title=" Stashing stashing iterators for proper flattening">P2770R0</a> in Issaquah. Status changed: New &rarr; Resolved.]</i></p>



<p id="res-3700"><b>Proposed resolution:</b></p>





</body>
</html>
