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