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 // Test the implicitly-generated copy and move constructors since `lazy_split_view` has non-trivial members.
13
14 #include <ranges>
15
16 #include <cassert>
17 #include <string_view>
18 #include <utility>
19 #include "types.h"
20
test()21 constexpr bool test() {
22 // Can copy `lazy_split_view`.
23 {
24 // Forward range.
25 {
26 std::ranges::lazy_split_view<std::string_view, std::string_view> v1("abc def", " ");
27 auto v2 = v1;
28 assert(v2.base() == v1.base());
29 }
30
31 // Input range.
32 {
33 SplitViewInput v1("abc def", ' ');
34 auto v2 = v1;
35 assert(v2.base() == v1.base());
36 }
37 }
38
39 // Can move `lazy_split_view`.
40 {
41 // Forward range.
42 {
43 std::string_view base = "abc def";
44 std::ranges::lazy_split_view<std::string_view, std::string_view> v1(base, " ");
45 auto v2 = std::move(v1);
46 assert(v2.base() == base);
47 }
48
49 // Input range.
50 {
51 InputView base("abc def");
52 SplitViewInput v1(base, ' ');
53 auto v2 = std::move(v1);
54 assert(v2.base() == base);
55 }
56 }
57
58 // `non-propagating-cache` is not copied.
59 {
60 SplitViewInput v1("abc def ghi", ' ');
61 auto outer_iter1 = v1.begin();
62 ++outer_iter1;
63 auto val1 = *outer_iter1;
64 auto i1 = val1.begin();
65 assert(*i1 == 'd');
66 ++i1;
67 assert(*i1 == 'e');
68
69 auto v2 = v1;
70 auto val2 = *v2.begin();
71 auto i2 = val2.begin();
72 assert(*i2 == 'a');
73 ++i2;
74 assert(*i2 == 'b');
75 }
76
77 return true;
78 }
79
main(int,char **)80 int main(int, char**) {
81 test();
82 static_assert(test());
83
84 return 0;
85 }
86