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