1 // Copyright (C) 2019-2020 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-options "-std=gnu++2a" } 19 // { dg-do compile { target c++2a } } 20 21 #include <ranges> 22 #include <testsuite_iterators.h> 23 24 static_assert( std::ranges::sized_range<int(&)[1]> ); 25 static_assert( std::ranges::sized_range<const int(&)[1]> ); 26 static_assert( std::ranges::sized_range<int[1]> ); 27 static_assert( !std::ranges::sized_range<int*> ); 28 29 using namespace __gnu_test; 30 31 // ranges::size(r) uses (end(r) - begin(r)) 32 static_assert( std::ranges::sized_range<test_contiguous_range<int>> ); 33 static_assert( std::ranges::sized_range<test_contiguous_range<int>&> ); 34 static_assert( std::ranges::sized_range<test_random_access_range<int>> ); 35 static_assert( std::ranges::sized_range<test_random_access_range<int>&> ); 36 // ranges::size(r) is invalid, (end(r) - begin(r)) requires sized sentinel 37 static_assert(!std::ranges::sized_range<test_bidirectional_range<int>> ); 38 static_assert(!std::ranges::sized_range<test_bidirectional_range<int>&> ); 39 static_assert(!std::ranges::sized_range<test_forward_range<int>> ); 40 static_assert(!std::ranges::sized_range<test_forward_range<int>&> ); 41 static_assert(!std::ranges::sized_range<test_input_range<int>> ); 42 static_assert(!std::ranges::sized_range<test_input_range<int>&> ); 43 static_assert(!std::ranges::sized_range<test_output_range<int>> ); 44 static_assert(!std::ranges::sized_range<test_output_range<int>&> ); 45 46 // ranges::size(r) uses r.size() 47 static_assert( std::ranges::sized_range<test_contiguous_sized_range<int>> ); 48 static_assert( std::ranges::sized_range<test_contiguous_sized_range<int>&> ); 49 static_assert( std::ranges::sized_range<test_random_access_sized_range<int>> ); 50 static_assert( std::ranges::sized_range<test_random_access_sized_range<int>&> ); 51 static_assert( std::ranges::sized_range<test_bidirectional_sized_range<int>> ); 52 static_assert( std::ranges::sized_range<test_bidirectional_sized_range<int>&> ); 53 static_assert( std::ranges::sized_range<test_forward_sized_range<int>> ); 54 static_assert( std::ranges::sized_range<test_forward_sized_range<int>&> ); 55 static_assert( std::ranges::sized_range<test_input_sized_range<int>> ); 56 static_assert( std::ranges::sized_range<test_input_sized_range<int>&> ); 57 static_assert( std::ranges::sized_range<test_output_sized_range<int>> ); 58 static_assert( std::ranges::sized_range<test_output_sized_range<int>&> ); 59 60 using long_range = __gnu_test::test_random_access_sized_range<long>; 61 template<> constexpr bool std::ranges::disable_sized_range<long_range> = true; 62 63 // Despite being disabled, this is still a sized_range because ranges::size(r) 64 // works, by using (ranges::end(r) - ranges::begin(r)). 65 static_assert( std::ranges::sized_range<long_range> ); 66 static_assert( std::ranges::sized_range<long_range&> ); 67 68 using short_range = __gnu_test::test_bidirectional_sized_range<short>; 69 template<> constexpr bool std::ranges::disable_sized_range<short_range> = true; 70 71 // This is not a sized range because ranges::size(r) cannot use member size, 72 // or ADL size, and (ranges::end(r) - ranges::begin(r)) is ill-formed for 73 // bidirectional iterators. 74 static_assert( !std::ranges::sized_range<short_range> ); 75 static_assert( !std::ranges::sized_range<short_range&> ); 76