// Copyright (C) 2020-2023 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // . // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } #include #include #include #include #include using __gnu_test::test_range; using __gnu_test::forward_iterator_wrapper; namespace ranges = std::ranges; namespace views = std::ranges::views; void test01() { auto p = [] (int i) { return i != 16; }; auto v = views::iota(10) | views::take_while(p); VERIFY( ranges::equal(v, (int[]){10,11,12,13,14,15}) ); using R = decltype(v); static_assert(ranges::view); static_assert(!ranges::common_range); static_assert(ranges::random_access_range); } void test02() { int x[] = {1,2,3,4,5}; test_range rx(x); auto v = rx | views::take_while([] (int i) { return i<4; }); VERIFY( ranges::equal(v, (int[]){1,2,3}) ); using R = decltype(v); static_assert(ranges::view); static_assert(!ranges::common_range); static_assert(ranges::forward_range); } void test03() { std::forward_list x = {1,2,3,4,5}; auto v = x | views::transform(std::negate{}) | views::take_while(std::identity{}); // Verify that _Sentinel is implicitly convertible to _Sentinel. static_assert(!ranges::common_range); static_assert(!std::same_as); auto b = ranges::cend(v); b = ranges::end(v); } void test04() { // LWG 3450 auto v = views::single(1) | views::take_while([](int& x) { return true;}); static_assert(ranges::range); static_assert(!ranges::range); } template void test05() { // Verify SFINAE behavior. extern int x[5]; auto p = [] (int*) { return true; }; static_assert(!requires { take_while(); }); static_assert(!requires { take_while(x, p, p); }); static_assert(!requires { take_while(x, p); }); static_assert(!requires { take_while(p)(x); }); static_assert(!requires { x | (take_while(p) | views::all); }); static_assert(!requires { (take_while(p) | views::all)(x); }); static_assert(!requires { take_while | views::all; }); static_assert(!requires { views::all | take_while; }); } int main() { test01(); test02(); test03(); test04(); test05(); }