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 | struct Pred { |
30 | constexpr bool operator()(int i) const { return i < 3; } |
31 | }; |
32 | |
33 | static_assert(HasEnd<std::ranges::drop_while_view<View, Pred>>); |
34 | static_assert(!HasEnd<const std::ranges::drop_while_view<View, Pred>>); |
35 | |
36 | constexpr bool test() { |
37 | // return iterator |
38 | { |
39 | int buffer[] = {1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1}; |
40 | std::ranges::drop_while_view dwv(buffer, Pred{}); |
41 | std::same_as<int*> decltype(auto) st = dwv.end(); |
42 | assert(st == 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, 3, 4, 5, 6, 5, 4, 3, 2, 1}; |
51 | Range range = {buffer, Sent{buffer + 11}}; |
52 | std::ranges::drop_while_view dwv(range, Pred{}); |
53 | std::same_as<Sent> decltype(auto) st = dwv.end(); |
54 | assert(base(st) == buffer + 11); |
55 | } |
56 | |
57 | return true; |
58 | } |
59 | |
60 | int main(int, char**) { |
61 | test(); |
62 | static_assert(test()); |
63 | return 0; |
64 | } |
65 | |