public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96704] New: begin() and end() iterators of views::values_view have different type
@ 2020-08-19 10:27 gleb at scylladb dot com
  2020-08-19 10:39 ` [Bug c++/96704] " gleb at scylladb dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gleb at scylladb dot com @ 2020-08-19 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96704
           Summary: begin() and end() iterators of views::values_view have
                    different type
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gleb at scylladb dot com
  Target Milestone: ---

The following program fail on the second assert.

#include <ranges>
#include <unordered_map>

int main() {
  std::unordered_map<int, int> x;
  auto r = std::views::values(x);
  static_assert(std::is_same_v<decltype(x.begin()), decltype(x.end())>);
  static_assert(std::is_same_v<decltype(r.begin()), decltype(r.end())>);
}

It means functions like:

template<typename I> foo(I it1, I it2);

cannot be called with:

foo(r.begin(), r.end());

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

* [Bug c++/96704] begin() and end() iterators of views::values_view have different type
  2020-08-19 10:27 [Bug c++/96704] New: begin() and end() iterators of views::values_view have different type gleb at scylladb dot com
@ 2020-08-19 10:39 ` gleb at scylladb dot com
  2020-08-19 10:41 ` gleb at scylladb dot com
  2020-08-19 11:24 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gleb at scylladb dot com @ 2020-08-19 10:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Gleb Natapov <gleb at scylladb dot com> ---
Ah, those appears to be sentinel iterators.

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

* [Bug c++/96704] begin() and end() iterators of views::values_view have different type
  2020-08-19 10:27 [Bug c++/96704] New: begin() and end() iterators of views::values_view have different type gleb at scylladb dot com
  2020-08-19 10:39 ` [Bug c++/96704] " gleb at scylladb dot com
@ 2020-08-19 10:41 ` gleb at scylladb dot com
  2020-08-19 11:24 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: gleb at scylladb dot com @ 2020-08-19 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

Gleb Natapov <gleb at scylladb dot com> changed:

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

--- Comment #2 from Gleb Natapov <gleb at scylladb dot com> ---
Closing.

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

* [Bug c++/96704] begin() and end() iterators of views::values_view have different type
  2020-08-19 10:27 [Bug c++/96704] New: begin() and end() iterators of views::values_view have different type gleb at scylladb dot com
  2020-08-19 10:39 ` [Bug c++/96704] " gleb at scylladb dot com
  2020-08-19 10:41 ` gleb at scylladb dot com
@ 2020-08-19 11:24 ` redi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-08-19 11:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right, it's incorrect to assume begin and end return the same type for a range.

Use std::common_iterator if you need to turn an iterator and its sentinel into
a single type:

  using CI = std::common_iterator<decltype(r.begin()), decltype(r.end())>;
  foo(CI(r.begin()), CI(r.end()));

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

end of thread, other threads:[~2020-08-19 11:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 10:27 [Bug c++/96704] New: begin() and end() iterators of views::values_view have different type gleb at scylladb dot com
2020-08-19 10:39 ` [Bug c++/96704] " gleb at scylladb dot com
2020-08-19 10:41 ` gleb at scylladb dot com
2020-08-19 11:24 ` 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).