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-has-no-incomplete-ranges
11
12 // constexpr decltype(auto) inner-iterator::operator*() const;
13
14 #include <ranges>
15
16 #include "../types.h"
17
test()18 constexpr bool test() {
19 // Can call `inner-iterator::operator*`; `View` is a forward range.
20 {
21 SplitViewDiff v("abc def", " ");
22 auto val = *v.begin();
23
24 // Non-const iterator.
25 {
26 auto i = val.begin();
27 static_assert(std::same_as<decltype(*i), char&>);
28 assert(*i == 'a');
29 assert(*(++i) == 'b');
30 assert(*(++i) == 'c');
31 }
32
33 // Const iterator.
34 {
35 const auto ci = val.begin();
36 static_assert(std::same_as<decltype(*ci), char&>);
37 assert(*ci == 'a');
38 }
39 }
40
41 // Can call `inner-iterator::operator*`; `View` is an input range.
42 {
43 SplitViewInput v("abc def", ' ');
44 auto val = *v.begin();
45
46 // Non-const iterator.
47 {
48 auto i = val.begin();
49 static_assert(std::same_as<decltype(*i), char&>);
50 assert(*i == 'a');
51 assert(*(++i) == 'b');
52 assert(*(++i) == 'c');
53 }
54
55 // Const iterator.
56 {
57 const auto ci = val.begin();
58 static_assert(std::same_as<decltype(*ci), char&>);
59 // Note: when the underlying range is an input range, `current` is stored in the `lazy_split_view` itself and
60 // shared between `inner-iterator`s. Consequently, incrementing one iterator effectively increments all of them.
61 assert(*ci == 'c');
62 }
63 }
64
65 return true;
66 }
67
main(int,char **)68 int main(int, char**) {
69 test();
70 static_assert(test());
71
72 return 0;
73 }
74