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