| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | // template<class T> |
| 12 | // concept sized_range; |
| 13 | |
| 14 | #include <ranges> |
| 15 | |
| 16 | #include "test_iterators.h" |
| 17 | |
| 18 | |
| 19 | |
| 20 | static_assert(std::ranges::sized_range<int[5]>); |
| 21 | static_assert(std::ranges::sized_range<int (&)[5]>); |
| 22 | static_assert(!std::ranges::sized_range<int (&)[]>); |
| 23 | static_assert(!std::ranges::sized_range<int[]>); |
| 24 | |
| 25 | struct range_has_size { |
| 26 | bidirectional_iterator<int*> begin(); |
| 27 | bidirectional_iterator<int*> end(); |
| 28 | int size(); |
| 29 | }; |
| 30 | static_assert(std::ranges::sized_range<range_has_size>); |
| 31 | static_assert(!std::ranges::sized_range<range_has_size const>); |
| 32 | |
| 33 | struct range_has_const_size { |
| 34 | bidirectional_iterator<int*> begin(); |
| 35 | bidirectional_iterator<int*> end(); |
| 36 | int size() const; |
| 37 | }; |
| 38 | static_assert(std::ranges::sized_range<range_has_const_size>); |
| 39 | static_assert(!std::ranges::sized_range<range_has_const_size const>); |
| 40 | |
| 41 | struct const_range_has_size { |
| 42 | bidirectional_iterator<int*> begin() const; |
| 43 | bidirectional_iterator<int*> end() const; |
| 44 | int size(); |
| 45 | }; |
| 46 | static_assert(std::ranges::sized_range<const_range_has_size>); |
| 47 | static_assert(std::ranges::range<const_range_has_size const>); |
| 48 | static_assert(!std::ranges::sized_range<const_range_has_size const>); |
| 49 | |
| 50 | struct const_range_has_const_size { |
| 51 | bidirectional_iterator<int*> begin() const; |
| 52 | bidirectional_iterator<int*> end() const; |
| 53 | int size() const; |
| 54 | }; |
| 55 | static_assert(std::ranges::sized_range<const_range_has_const_size>); |
| 56 | static_assert(std::ranges::sized_range<const_range_has_const_size const>); |
| 57 | |
| 58 | struct sized_sentinel_range_has_size { |
| 59 | int* begin(); |
| 60 | int* end(); |
| 61 | }; |
| 62 | static_assert(std::ranges::sized_range<sized_sentinel_range_has_size>); |
| 63 | static_assert(!std::ranges::sized_range<sized_sentinel_range_has_size const>); |
| 64 | |
| 65 | struct const_sized_sentinel_range_has_size { |
| 66 | int* begin() const; |
| 67 | int* end() const; |
| 68 | }; |
| 69 | static_assert(std::ranges::sized_range<const_sized_sentinel_range_has_size>); |
| 70 | static_assert(std::ranges::sized_range<const_sized_sentinel_range_has_size const>); |
| 71 | |
| 72 | struct non_range_has_size { |
| 73 | int size() const; |
| 74 | }; |
| 75 | static_assert(requires(non_range_has_size const x) { std::ranges::size(x); }); |
| 76 | static_assert(!std::ranges::sized_range<non_range_has_size>); |
| 77 | static_assert(!std::ranges::sized_range<non_range_has_size const>); |
| 78 | |