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+ // REQUIRES: std-at-least-c++26
10+
11+ // <optional>
12+
13+ // template <class T> class optional<T&>::iterator;
14+ // template <class T> class optional<T&>::const_iterator;
15+ // template <class T>
16+ // constexpr bool ranges::enable_borrowed_range<optional<T&>> = true;
17+
18+ #include < cassert>
19+ #include < optional>
20+ #include < ranges>
21+
22+ template <typename T>
23+ constexpr bool enable_borrowed_range () {
24+ {
25+ assert (std::ranges::enable_borrowed_range<std::optional<T&>>);
26+ }
27+ return true ;
28+ }
29+
30+ template <typename T>
31+ constexpr bool borrowed_range () {
32+ if (std::ranges::range<std::optional<T&>>) {
33+ assert (std::ranges::borrowed_range<std::optional<T&>>);
34+ } else {
35+ assert (!std::ranges::borrowed_range<std::optional<T&>>);
36+ return false ;
37+ }
38+
39+ return true ;
40+ }
41+
42+ constexpr bool test_enable_borrowed_range () {
43+ assert (enable_borrowed_range<int >());
44+ assert (enable_borrowed_range<const int >());
45+ assert (enable_borrowed_range<int []>());
46+ assert (enable_borrowed_range<int [10 ]>());
47+ assert (enable_borrowed_range<int ()>());
48+
49+ return true ;
50+ }
51+
52+ constexpr bool test_borrowed_range () {
53+ assert (borrowed_range<int >());
54+ assert (borrowed_range<const int >());
55+ assert (!borrowed_range<int []>());
56+ assert (!borrowed_range<int [10 ]>());
57+ assert (!borrowed_range<int ()>());
58+
59+ return true ;
60+ }
61+
62+ int main (int , char **) {
63+ {
64+ static_assert (test_enable_borrowed_range ());
65+ assert (test_enable_borrowed_range ());
66+ }
67+
68+ {
69+ static_assert (test_borrowed_range ());
70+ assert (test_enable_borrowed_range ());
71+ }
72+
73+ return 0 ;
74+ }
0 commit comments