<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3685: In lazy_split_view, CTAD doesn't work when given an input_range input and a tiny-range pattern</title>
<meta property="og:title" content="Issue 3685: In lazy_split_view, CTAD doesn't work when given an input_range input and a tiny-range pattern">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3685.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#New">New</a> status.</em></p>
<h3 id="3685"><a href="lwg-active.html#3685">3685</a>. In <code>lazy_split_view</code>, CTAD doesn't work when given an <code>input_range</code> input and a <code><i>tiny-range</i></code> pattern</h3>
<p><b>Section:</b> 25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Konstantin Varlamov <b>Opened:</b> 2022-03-23 <b>Last modified:</b> 2022-05-17</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#range.lazy.split.view">active issues</a> in [range.lazy.split.view].</p>
<p><b>View all other</b> <a href="lwg-index.html#range.lazy.split.view">issues</a> in [range.lazy.split.view].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In <code>lazy_split_view</code>, the deduction guide that accepts two arbitrary types wraps the arguments in 
<code>views::all_t</code> (25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a>):
</p>
<blockquote><pre>
template&lt;class R, class P&gt;
  lazy_split_view(R&amp;&amp;, P&amp;&amp;) -&gt; lazy_split_view&lt;views::all_t&lt;R&gt;, views::all_t&lt;P&gt;&gt;;
</pre></blockquote>
<p>
When trying to use an <code>input_range</code> as the input, <code>lazy_split_view</code> requires the pattern 
type to satisfy the exposition-only concept <code><i>tiny-range</i></code>. Trying to use CTAD with an 
<code>input_range</code> and a <code><i>tiny-range</i></code> as arguments results in a compiler error, as demonstrated
in the <a href="https://godbolt.org/z/37bs9hq1T">demo link</a>:
</p>
<blockquote><pre>
// Assuming <code class='backtick'>InputRange</code> and <code class='backtick'>TinyRange</code> are valid types satisfying the
// corresponding concepts.
std::ranges::lazy_split_view view{InputRange(), TinyRange()}; // Compiler error
</pre></blockquote>
<p>
The underlying reason is that <code><i>tiny-range</i></code> requires the given type to contain a static member function 
<code>size()</code> that returns a number <code>&lt;=1</code> (25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a>):
</p>
<blockquote><pre>
template&lt;class R&gt;
  concept <i>tiny-range</i> =                                          // exposition only
    sized_range&lt;R&gt; &amp;&amp;
    requires { typename <i>require-constant</i>&lt;remove_reference_t&lt;R&gt;::size()&gt;; } &amp;&amp;
    (remove_reference_t&lt;R&gt;::size() &lt;= 1);
</pre></blockquote>
<p>
However, when given a range, <code>views::all_t</code> wraps the type in a <code>ranges::owning_view</code>. 
<code>owning_view</code> doesn't satisfy <code><i>tiny-range</i></code> for any template parameter because it 
never contains the static <code>size()</code> function required by the concept.
<p/>
A general resolution might be modifying <code>owning_view</code> so that it satisfies <code><i>tiny-range</i></code> 
when the given type is a <code><i>tiny-range</i></code> (that would require moving the <code><i>tiny-range</i></code> 
concept from 25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a> to 25.5.2 <a href="https://wg21.link/range.utility.helpers">[range.utility.helpers]</a>). A more 
localized solution can be to change the deduction guide in <code>lazy_split_view</code> to avoid wrapping 
a type satisfying <code><i>tiny-range</i></code> in <code>views::all_t</code>.
</p>

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

<p>
Set priority to 3 after reflector poll. One vote for NAD.
</p>



<p id="res-3685"><b>Proposed resolution:</b></p>
<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.5.2 <a href="https://wg21.link/range.utility.helpers">[range.utility.helpers]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> This change effectively just moves the definitions of 
<code><i>require-constant</i></code> and <code><i>tiny-range</i></code> from 25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a>
to 25.5.2 <a href="https://wg21.link/range.utility.helpers">[range.utility.helpers]</a>.]
</p>
</blockquote>

<blockquote>
<pre>
[&hellip;]
template&lt;class T, class U&gt;
  concept <i>different-from</i> = <i>// exposition only</i>
    !same_as&lt;remove_cvref_t&lt;T&gt;, remove_cvref_t&lt;U&gt;&gt;;

<ins>template&lt;auto&gt; struct <i>require-constant</i>; <i>// exposition only</i>

template&lt;class R&gt;
concept <i>tiny-range</i> = <i>// exposition only</i>
  sized_range&lt;R&gt; &amp;&amp;
  requires { typename <i>require-constant</i>&lt;remove_reference_t&lt;R&gt;::size()&gt;; } &amp;&amp;
  (remove_reference_t&lt;R&gt;::size() &lt;= 1);</ins>
</pre>
</blockquote>
</li>

<li><p>Modify 25.7.6.3 <a href="https://wg21.link/range.owning.view">[range.owning.view]</a>, class template <code>owning_view</code> synopsis, as indicated:</p>

<blockquote>
<pre>
[&hellip;]
<ins>constexpr static auto size() requires <i>tiny-range</i>&lt;R&gt;
{ return R::size(); }</ins>
constexpr auto size() requires sized_range&lt;R&gt;
{ return ranges::size(<i>r_</i>); }
constexpr auto size() const requires sized_range&lt;const R&gt;
{ return ranges::size(<i>r_</i>); }
[&hellip;]
</pre>
</blockquote>
</li>

<li><p>Modify 25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a>, class template <code>lazy_split_view</code> synopsis, as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> This change effectively just moves the definitions of 
<code><i>require-constant</i></code> and <code><i>tiny-range</i></code> from 25.7.16.2 <a href="https://wg21.link/range.lazy.split.view">[range.lazy.split.view]</a>
to 25.5.2 <a href="https://wg21.link/range.utility.helpers">[range.utility.helpers]</a>.]
</p>
</blockquote>

<blockquote>
<pre>
namespace std::ranges {
  <del>template&lt;auto&gt; struct <i>require-constant</i>; <i>// exposition only</i>
  
  template&lt;class R&gt;
  concept <i>tiny-range</i> = <i>// exposition only</i>
    sized_range&lt;R&gt; &amp;&amp;
    requires { typename <i>require-constant</i>&lt;remove_reference_t&lt;R&gt;::size()&gt;; } &amp;&amp;
    (remove_reference_t&lt;R&gt;::size() &lt;= 1);</del>
    
  template&lt;input_range V, forward_range Pattern&gt;
    requires view&lt;V&gt; &amp;&amp; view&lt;Pattern&gt; &amp;&amp;
             indirectly_comparable&lt;iterator_t&lt;V&gt;, iterator_t&lt;Pattern&gt;, ranges::equal_to&gt; &amp;&amp;
             (forward_range&lt;V&gt; || <i>tiny-range</i>&lt;Pattern&gt;)
  class lazy_split_view : public view_interface&lt;lazy_split_view&lt;V, Pattern&gt;&gt; {
    [&hellip;]
  };
  [&hellip;]
}
</pre>
</blockquote>
</li>
</ol>





</body>
</html>
