Bug 104801 - std::ranges::view_interface::empty is overconstrained
Summary: std::ranges::view_interface::empty is overconstrained
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-05 21:16 UTC by Pawel P
Modified: 2022-03-06 12:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel P 2022-03-05 21:16:44 UTC
I can't see why empty() needs a forward_iterator. It looks overconstrained and input_iterator should suffice because it is equivalent to the begin/end iterator comparison, yet, somehow this does not compile:

auto is = std::istringstream{"1 2 3"};
auto v = ranges::istream_view<int>(is);
{
  auto is_empty = v.empty();  // error
}

{
  auto [begin, end] = std::subrange(v);
  auto is_empty = begin == end;  // works
}
Comment 1 康桓瑋 2022-03-06 04:16:56 UTC
Because istream_view is a single pass range, once you call its begin(), it will change the internal state.
Comment 2 Pawel P 2022-03-06 12:32:03 UTC
I understand. Thank you for clarification
Comment 3 康桓瑋 2022-03-06 12:37:27 UTC
(In reply to Pawel P from comment #2)
> I understand. Thank you for clarification

You should close with RESOLVED INVALID since there is nothing to fix.