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