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 // constexpr auto end();
12
13 #include <cassert>
14 #include <ranges>
15 #include <type_traits>
16 #include <utility>
17
18 #include "test_iterators.h"
19
20 struct View : std::ranges::view_base {
21 int* begin() const;
22 int* end() const;
23 };
24
25 // Test that end is not const
26 template <class T>
27 concept HasEnd = requires(T t) { t.end(); };
28
29 static_assert(HasEnd<std::ranges::split_view<View, View>>);
30 static_assert(!HasEnd<const std::ranges::split_view<View, View>>);
31
test()32 constexpr bool test() {
33 // return iterator
34 {
35 int buffer[] = {1, 2, -1, 4, 5, 6, 5, 4, -1, 2, 1};
36 auto inputView = std::views::all(buffer);
37 static_assert(std::ranges::common_range<decltype(inputView)>);
38
39 std::ranges::split_view sv(buffer, -1);
40 using SplitIter = std::ranges::iterator_t<decltype(sv)>;
41 std::same_as<SplitIter> decltype(auto) sentinel = sv.end();
42 assert(sentinel.base() == buffer + 11);
43 }
44
45 // return sentinel
46 {
47 using Iter = int*;
48 using Sent = sentinel_wrapper<Iter>;
49 using Range = std::ranges::subrange<Iter, Sent>;
50 int buffer[] = {1, 2, -1, 4, 5, 6, 5, 4, -1, 2, 1};
51 Range range = {buffer, Sent{buffer + 11}};
52 static_assert(!std::ranges::common_range<Range>);
53
54 std::ranges::split_view sv(range, -1);
55 auto sentinel = sv.end();
56
57 using SplitIter = std::ranges::iterator_t<decltype(sv)>;
58 static_assert(!std::same_as<decltype(sentinel), SplitIter>);
59
60 assert(std::next(sv.begin(), 3) == sentinel);
61 }
62
63 return true;
64 }
65
main(int,char **)66 int main(int, char**) {
67 test();
68 static_assert(test());
69 return 0;
70 }
71