| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 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) |
| 7 |
// any later version. |
| 8 |
|
| 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. |
| 13 |
|
| 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/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++20 } } |
| 19 |
|
| 20 |
#include <ranges> |
| 21 |
#include <testsuite_iterators.h> |
| 22 |
|
| 23 |
using __gnu_test::test_forward_range; |
| 24 |
|
| 25 |
void |
| 26 |
test01() |
| 27 |
{ |
| 28 |
// PR libstdc++/95322 and LWG 3448 |
| 29 |
int a[2]{1, 2}; |
| 30 |
test_forward_range<int> v{a}; |
| 31 |
auto view1 = v | std::views::take(2); |
| 32 |
auto view2 = view1 | std::views::transform(std::identity{}); |
| 33 |
const bool eq = std::ranges::cbegin(view2) == std::ranges::end(view2); |
| 34 |
VERIFY( !eq ); |
| 35 |
} |
| 36 |
|
| 37 |
void |
| 38 |
test02() |
| 39 |
{ |
| 40 |
using irange = test_forward_range<int>; |
| 41 |
|
| 42 |
int a[2]{1, 2}; |
| 43 |
int b[3]{3, 4, 5}; |
| 44 |
irange u[2]{ irange{a}, irange{b} }; |
| 45 |
test_forward_range<irange> v{u}; |
| 46 |
auto view = (std::views::counted(v.begin(), 2) |
| 47 |
| std::views::transform(std::identity{}) |
| 48 |
| std::views::join); |
| 49 |
const bool eq = std::ranges::cbegin(view) == std::ranges::end(view); |
| 50 |
VERIFY( !eq ); |
| 51 |
} |
| 52 |
|
| 53 |
void |
| 54 |
test03() |
| 55 |
{ |
| 56 |
// LWG 3449, for take_view |
| 57 |
int a[2]{1, 2}; |
| 58 |
test_forward_range<int> v{a}; |
| 59 |
auto view1 = v | std::views::transform(std::identity{}); |
| 60 |
auto view2 = view1 | std::views::take(2); |
| 61 |
const bool eq = std::ranges::cbegin(view2) == std::ranges::end(view2); |
| 62 |
VERIFY( !eq ); |
| 63 |
} |
| 64 |
|
| 65 |
void |
| 66 |
test04() |
| 67 |
{ |
| 68 |
// LWG 3449, for take_while_view |
| 69 |
int a[2]{1, 2}; |
| 70 |
test_forward_range<int> v{a}; |
| 71 |
auto view1 = v | std::views::transform(std::identity{}); |
| 72 |
auto view2 = view1 | std::views::take_while([] (int i) { return true; }); |
| 73 |
const bool eq = std::ranges::cbegin(view2) == std::ranges::end(view2); |
| 74 |
VERIFY( !eq ); |
| 75 |
} |
| 76 |
|
| 77 |
int main() |
| 78 |
{ |
| 79 |
test01(); |
| 80 |
test02(); |
| 81 |
test03(); |
| 82 |
test04(); |
| 83 |
} |