title: Create ranges custom view functions (operator() and operator|)
body: <p>I'm currently trying to wrap my head around the upcoming std::ranges. As an exercise I'd like to implement a "toupper" view from scratch which takes a range/view over some characters and transforms those to upper case.</p>
  
  <p>Hacking together a view and some iterator was pretty straight forward, I don't get how operator() and | have to be overloaded in order to compose like the rest of ranges does though.</p>
  
  <p>Here is the "toupper_fn" (to follow the ranges naming convention) I came up with so far. This is pretty much a copy/paste of some view function inside the ranges v3:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>    struct toupper_fn {
        template &lt;typename Rng&gt;
        auto operator()(Rng&amp;&amp; rng) const {
          return toupper_view{std::forward&lt;Rng&gt;(rng)};
        }
  
        template &lt;typename Rng&gt;
        friend auto operator|(Rng&amp;&amp; rng, toupper_fn&amp; c)
            -&gt; decltype(c(std::forward&lt;Rng&gt;(rng))) {
          return c(std::forward&lt;Rng&gt;(rng));
        }
  
        template &lt;typename Rng&gt;
        friend auto operator|(Rng&amp;&amp; rng, toupper_fn const&amp; c)
            -&gt; decltype(c(std::forward&lt;Rng&gt;(rng))) {
          return c(std::forward&lt;Rng&gt;(rng));
        }
  
        template &lt;typename Rng&gt;
        friend auto operator|(Rng&amp;&amp; rng, toupper_fn&amp;&amp; c)
            -&gt; decltype(std::move(c)(std::forward&lt;Rng&gt;(rng))) {
          return std::move(c)(std::forward&lt;Rng&gt;(rng));
        }
      };
  </code></pre>
  
  <p>The problem is that with those definitions both, the classic function call syntax (view(view...)) and the pipe syntax, only work if my own view is the last in the chain.</p>
  
  <p>Here is the whole code on godbolt -></p>
  
  <p>Either with ranges-v3: <a href="https://godbolt.org/z/6RlNVC" rel="noreferrer">https://godbolt.org/z/6RlNVC</a></p>
  
  <p>Or cmcstl2: <a href="https://godbolt.org/z/wba_yW" rel="noreferrer">https://godbolt.org/z/wba_yW</a></p>