ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 441 forks source link

istream_view missing from ranges::cpp20 namespace #1324

Open JeffGarland opened 5 years ago

JeffGarland commented 5 years ago

From the docs I get the impression we should now be able to use ranges::cpp20. This compiles and works fine just using the ranges:: namespace.

#include <range/v3/all.hpp> 
#include <vector>
#include <iostream>
#include <sstream>
using std::cout, std::vector;

int main() {

  auto ints = std::istringstream{"0 1 2 3 4"}; 

  for (int i : ranges::cpp20::istream_view<int>(ints)) { 
      cout << i << "-"; // prints 0-1-2-3-4-
  }
}

https://godbolt.org/z/9fmFJX


<source>: In function 'int main()':
<source>:13:31: error: 'istream_view' is not a member of 'ranges::cpp20'; did you mean 'ranges::istream_view'?
   13 |   for (int i : ranges::cpp20::istream_view<int>(ints)) {
      |                               ^~~~~~~~~~~~
In file included from /opt/compiler-explorer/libs/rangesv3/trunk/include/range/v3/action/action.hpp:21,
                 from /opt/compiler-explorer/libs/rangesv3/trunk/include/range/v3/action.hpp:17,
                 from /opt/compiler-explorer/libs/rangesv3/trunk/include/range/v3/all.hpp:17,
                 from <source>:3:
/opt/compiler-explorer/libs/rangesv3/trunk/include/range/v3/range_fwd.hpp:464:12: note: 'ranges::istream_view' declared here
  464 |     struct istream_view;
      |            ^~~~~~~~~~~~
<source>:13:44: error: expected primary-expression before 'int'
   13 |   for (int i : ranges::cpp20::istream_view<int>(ints)) {
      |                                            ^~~
<source>:13:44: error: expected ')' before 'int'
   13 |   for (int i : ranges::cpp20::istream_view<int>(ints)) {
      |       ~                                    ^~~
      |                                            )
<source>:13:47: error: expected unqualified-id before '>' token
   13 |   for (int i : ranges::cpp20::istream_view<int>(ints)) {
      |                                               ^
Compiler returned: 1
h-2 commented 5 years ago

It's called basic_istream_view in cpp20. It was missing from the namespace, but I added it last week. Can you update to the current master and check if you find it?

JeffGarland commented 5 years ago

I was up to date with trunk as of yesterday, I assume it's there :) However:

relative to N4830 - section 24.7.15.2 [range.istream.view]

para 3:

template<class Val, class CharT, class Traits>
basic_istream_view<Val, CharT, Traits> istream_view(basic_istream<CharT, Traits>& s);

Effects: Equivalent to: return basic_istream_view<Val, CharT, Traits>{s};

see also example in range.take.while.overview

    auto input = istringstream{"0 1 2 3 4 5 6 7 8 9"};
     auto small = [](const auto x) noexcept { return x < 5; };
     auto small_ints = istream_view<int>(input) | views::take_while(small);
h-2 commented 5 years ago

Ah, you are correct. I overlooked that one.