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 | // class std::ranges::subrange; |
12 | |
13 | #include <ranges> |
14 | |
15 | #include <cassert> |
16 | #include <cstddef> |
17 | |
18 | #include "test_iterators.h" |
19 | |
20 | using FI = forward_iterator<int*>; |
21 | FI fi{nullptr}; |
22 | int *ptr = nullptr; |
23 | |
24 | static_assert(std::same_as<decltype(std::ranges::subrange(fi, fi)), |
25 | std::ranges::subrange<FI, FI, std::ranges::subrange_kind::unsized>>); |
26 | static_assert(std::same_as<decltype(std::ranges::subrange(ptr, ptr, 0)), |
27 | std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); |
28 | static_assert(std::same_as<decltype(std::ranges::subrange(ptr, nullptr, 0)), |
29 | std::ranges::subrange<int*, std::nullptr_t, std::ranges::subrange_kind::sized>>); |
30 | |
31 | struct ForwardRange { |
32 | forward_iterator<int*> begin() const; |
33 | forward_iterator<int*> end() const; |
34 | }; |
35 | template<> |
36 | inline constexpr bool std::ranges::enable_borrowed_range<ForwardRange> = true; |
37 | |
38 | struct SizedRange { |
39 | int *begin(); |
40 | int *end(); |
41 | }; |
42 | template<> |
43 | inline constexpr bool std::ranges::enable_borrowed_range<SizedRange> = true; |
44 | |
45 | static_assert(std::same_as<decltype(std::ranges::subrange(ForwardRange())), |
46 | std::ranges::subrange<FI, FI, std::ranges::subrange_kind::unsized>>); |
47 | static_assert(std::same_as<decltype(std::ranges::subrange(SizedRange())), |
48 | std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); |
49 | static_assert(std::same_as<decltype(std::ranges::subrange(SizedRange(), 8)), |
50 | std::ranges::subrange<int*, int*, std::ranges::subrange_kind::sized>>); |
51 | |