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 // class std::ranges::lazy_split_view;
13 
14 #include <ranges>
15 
16 #include <cassert>
17 #include <concepts>
18 #include <string_view>
19 #include <type_traits>
20 #include "types.h"
21 
22 using V = SplitViewForward;
23 
24 static_assert(std::is_base_of_v<std::ranges::view_interface<SplitViewForward>, SplitViewForward>);
25 
test()26 constexpr bool test() {
27   using namespace std::string_view_literals;
28 
29   // empty()
30   {
31     {
32       std::ranges::lazy_split_view v("abc def", " ");
33       assert(!v.empty());
34     }
35 
36     {
37       // Note: an empty string literal would still produce a non-empty output because the terminating zero is treated as
38       // a separate character; hence the use of `string_view`.
39       std::ranges::lazy_split_view v(""sv, "");
40       assert(v.empty());
41     }
42   }
43 
44   // operator bool()
45   {
46     {
47       std::ranges::lazy_split_view v("abc", "");
48       assert(v);
49     }
50 
51     {
52       // Note: an empty string literal would still produce a non-empty output because the terminating zero is treated as
53       // a separate character; hence the use of `string_view`.
54       std::ranges::lazy_split_view v(""sv, "");
55       assert(!v);
56     }
57   }
58 
59   // front()
60   {
61     SplitViewForward v("abc", "");
62     assert(*(v.front()).begin() == 'a');
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