1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
24 #include <testsuite_hooks.h>
25 #include <testsuite_iterators.h>
26 #include <testsuite_rvalref.h>
28 namespace ranges
= std::ranges
;
29 namespace views
= std::views
;
31 struct X
: __gnu_test::rvalstruct
36 operator>>(std::istream
& is
, X
& m
)
47 std::string s
= "0123456789";
48 auto ss
= std::istringstream
{s
};
49 auto v
= ranges::istream_view
<X
>(ss
);
50 VERIFY( ranges::equal(v
, s
, {}, &X::c
) );
56 auto ints
= std::istringstream
{"0 1 2 3 4"};
58 ranges::copy(ranges::istream_view
<int>(ints
), x
);
59 VERIFY( ranges::equal(x
, (int[]){0,1,2,3,4}) );
65 auto input
= std::istringstream
{"0 1 2 3 4 5 6 7 8 9"};
66 auto small
= [](const auto x
) noexcept
{ return x
< 5; };
67 auto v
= ranges::istream_view
<int>(input
) | views::take_while(small
);
68 VERIFY( ranges::equal(v
, (int[]){0,1,2,3,4}) );
72 concept has_iterator_category
= requires
{ typename
T::iterator_category
; };
77 std::istringstream
s("12345");
78 auto v
= ranges::istream_view
<char>(s
);
80 using It
= ranges::iterator_t
<decltype(v
)>;
81 static_assert(!has_iterator_category
<It
>);
82 static_assert(std::input_iterator
<It
>);
83 static_assert(!std::forward_iterator
<It
>);
89 // PR libstdc++/101231
90 auto words
= std::istringstream
{"42"};
91 auto is
= ranges::istream_view
<int>(words
);
92 auto r
= is
| views::filter([](auto) { return true; });
100 // Default template argument
101 using V
= std::ranges::basic_istream_view
<int, char>;
102 using W
= std::ranges::basic_istream_view
<int, char, std::char_traits
<char>>;
103 static_assert( std::is_same_v
<V
, W
> );
109 // P2432R1, views::istream
110 auto nums
= std::istringstream("0 1 2 3 4");
111 ranges::istream_view
<int> v(nums
);
113 for (int val
: views::istream
<int>(nums
))