public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gcc-bugs at marehr dot dialup.fu-berlin.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96070] New: std::views::* won't work with non-legacy iterators Date: Mon, 06 Jul 2020 02:08:09 +0000 [thread overview] Message-ID: <bug-96070-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96070 Bug ID: 96070 Summary: std::views::* won't work with non-legacy iterators Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de Target Milestone: --- Hi gcc-team, not long ago a filed a bug-report[1] that `std::ranges::basic_istream_view::iterator` has no `std::iterator_traits` entry. > Your mistake is thinking that the iterators of views are like the iterators you're used to. It seems that not only I had that problem, because this has some interesting consequences for the standard, for example the `std::ranges::filter_view::iterator` is described as [2]: > 3 iterator::iterator_category is defined as follows: > (3.1) Let C denote the type iterator_traits<iterator_t<V>>::iterator_category. > (3.2) If C models derived_from<bidirectional_iterator_tag>, then iterator_category denotes bidirectional_iterator_tag. > (3.3) Otherwise, if C models derived_from<forward_iterator_tag>, then iterator_category denotes forward_iterator_tag. > (3.4) Otherwise, iterator_category denotes C. This assumes that `iterator_traits<iterator_t<V>>::iterator_category` is defined which is not true for all iterators, like `std::ranges::basic_istream_view::iterator`. A quick check with the gcc stdlib implementation: ```c++ #include <iostream> #include <ranges> #include <vector> int main() { // using input_view_t = std::vector<int> &; // works using input_view_t = std::ranges::basic_istream_view<char, char, std::char_traits<char>>; // does not work auto accept_all = [](auto &&){return true;}; using filter_input_view_t = decltype(std::declval<input_view_t>() | std::views::filter(accept_all)); using filter_iterator_t = std::ranges::iterator_t<filter_input_view_t>; } ``` https://godbolt.org/z/Uozktw And yes it does not work. Since I don't know of a generic way to conditionally include/exclude `using iterator_category = some_tag`, I think the easiest way would to allow `iterator_category = void`. We would need to change the behaviour of `std::iterator_traits`. We should not only check whether all 4 members are available, but also that `iterator_category` is at least an input_iterator_tag or an output_iterator_tag. Or alternatively check that `iterator_category` is non-void. I don't know how to create a LWG issue and if this problem was already reported, but I hope you can create one like in my last finding [3]. If this defect was not reported yet, it would be nice to at least link back to this issue and not just write "A user reported that this doesn't compile: ". [1] - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94674 [2] - https://eel.is/c++draft/range.filter.iterator#3 [3] - https://cplusplus.github.io/LWG/issue3448
next reply other threads:[~2020-07-06 2:08 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-06 2:08 gcc-bugs at marehr dot dialup.fu-berlin.de [this message] 2020-07-06 10:50 ` [Bug libstdc++/96070] " redi at gcc dot gnu.org 2020-07-08 20:06 ` redi at gcc dot gnu.org 2021-04-20 15:38 ` ppalka at gcc dot gnu.org 2021-04-20 15:39 ` ppalka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-96070-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).