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

source code of libcxx/test/std/ranges/range.adaptors/range.lazy.split/ctor.copy_move.pass.cpp