public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95100] New: <ranges> xxx_view adaptors don't work with pipeline operator
@ 2020-05-13  8:37 rhalbersma at gmail dot com
  2020-05-15 14:10 ` [Bug c++/95100] " ppalka at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: rhalbersma at gmail dot com @ 2020-05-13  8:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95100

            Bug ID: 95100
           Summary: <ranges> xxx_view adaptors don't work with pipeline
                    operator
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rhalbersma at gmail dot com
  Target Milestone: ---

Combining the std::ranges::xxx_view adaptors with the pipeline operator does
not compile, in contrast to the supposedly expression equivalent
std::ranges:views::xxx 

#include <iostream>
#include <ranges> 
#include <vector>

int main() {
    auto v = std::vector { 1, 2, 3, 4, 5, 6 };

    // OK
    for (auto elem : std::ranges::views::reverse(v)) {
        std::cout << elem << ',';
    }

    // OK    
    for (auto elem : std::ranges::reverse_view(v)) {
        std::cout << elem << ',';
    }

    // OK
    for (auto elem : v | std::ranges::views::reverse) {
        std::cout << elem << ',';
    }

    // error: missing template arguments before ')' token
    for (auto elem : v | std::ranges::reverse_view) {
        std::cout << elem << ',';
    }

    // OK
    for (auto elem : v | std::ranges::views::transform([](auto e) { return e +
1; })) {
        std::cout << elem << ',';
    }    

    // error: class template argument deduction failed:
    for (auto elem : v | std::ranges::transform_view([](auto e) { return e + 1;
})) {
        std::cout << elem << ',';
    }
}

See online example on Wandbox here:
https://wandbox.org/permlink/E6ScFmm8DdmkFo74

Tested this also for drop_view, take_view, filter_view etc., with similar
results (not shown for brevity in the code snippet).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/95100] <ranges> xxx_view adaptors don't work with pipeline operator
  2020-05-13  8:37 [Bug c++/95100] New: <ranges> xxx_view adaptors don't work with pipeline operator rhalbersma at gmail dot com
@ 2020-05-15 14:10 ` ppalka at gcc dot gnu.org
  2020-05-15 22:54 ` rhalbersma at gmail dot com
  2020-05-16  9:02 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-05-15 14:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95100

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to rhalbersma from comment #0)
> Combining the std::ranges::xxx_view adaptors with the pipeline operator does
> not compile, in contrast to the supposedly expression equivalent
> std::ranges:views::xxx 

Hmm, I don't see anything in the spec that would imply views::xxx should be
expression-equivalent to xxx_view.  What I see is that views::xxx(E) is, for
some values of E, expression-equivalent to xxx_view{E}.

For instance [range.reverse.overview] says:

   Given a subexpression E, the expression views​::​reverse(E) is
expression-equivalent to: 
   [...]
   - Otherwise, equivalent to reverse_­view{E}.

Could you point me to the relevant bits of the spec that would imply this
stronger expression-equivalence?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/95100] <ranges> xxx_view adaptors don't work with pipeline operator
  2020-05-13  8:37 [Bug c++/95100] New: <ranges> xxx_view adaptors don't work with pipeline operator rhalbersma at gmail dot com
  2020-05-15 14:10 ` [Bug c++/95100] " ppalka at gcc dot gnu.org
@ 2020-05-15 22:54 ` rhalbersma at gmail dot com
  2020-05-16  9:02 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rhalbersma at gmail dot com @ 2020-05-15 22:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95100

--- Comment #2 from rhalbersma <rhalbersma at gmail dot com> ---
OK, so the rewriting rules [range.adaptors]/4, that make views::xxx(R)
equivalent to R | views::xxx, do not allow to rewrite the expression equivalent
xxx_view{R} as R | xxx_view? That would be rather finicky, perhaps even a
defect in the Standard?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/95100] <ranges> xxx_view adaptors don't work with pipeline operator
  2020-05-13  8:37 [Bug c++/95100] New: <ranges> xxx_view adaptors don't work with pipeline operator rhalbersma at gmail dot com
  2020-05-15 14:10 ` [Bug c++/95100] " ppalka at gcc dot gnu.org
  2020-05-15 22:54 ` rhalbersma at gmail dot com
@ 2020-05-16  9:02 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-16  9:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95100

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, it's not a rewriting rule. It says that the library implementation needs to
give range adaptor objects an overloaded operator| that allows them to be used
that way.

There's no magical rewriting going on, just operator overloading. You can't
overload an operator to take a class template as an argument.

Class templates are not objects and objects are not class templates.

Not a bug and not a defect.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-16  9:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13  8:37 [Bug c++/95100] New: <ranges> xxx_view adaptors don't work with pipeline operator rhalbersma at gmail dot com
2020-05-15 14:10 ` [Bug c++/95100] " ppalka at gcc dot gnu.org
2020-05-15 22:54 ` rhalbersma at gmail dot com
2020-05-16  9:02 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).