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 | // class transform_view::<sentinel>; |
12 | |
13 | #include <ranges> |
14 | |
15 | #include "test_macros.h" |
16 | #include "../types.h" |
17 | |
18 | template<class T> |
19 | concept EndIsIter = requires(T t) { ++t.end(); }; |
20 | |
21 | constexpr bool test() { |
22 | std::ranges::transform_view<SizedSentinelView, PlusOne> transformView1; |
23 | // Going to const and back. |
24 | auto sent1 = transformView1.end(); |
25 | std::ranges::sentinel_t<const std::ranges::transform_view<SizedSentinelView, PlusOne>> sent2{sent1}; |
26 | std::ranges::sentinel_t<const std::ranges::transform_view<SizedSentinelView, PlusOne>> sent3{sent2}; |
27 | (void)sent3; |
28 | |
29 | static_assert(!EndIsIter<decltype(sent1)>); |
30 | static_assert(!EndIsIter<decltype(sent2)>); |
31 | assert(sent1.base() == globalBuff + 8); |
32 | |
33 | std::ranges::transform_view transformView2(SizedSentinelView{4}, PlusOne()); |
34 | auto sent4 = transformView2.end(); |
35 | auto iter = transformView1.begin(); |
36 | { |
37 | assert(iter != sent1); |
38 | assert(iter != sent2); |
39 | assert(iter != sent4); |
40 | } |
41 | |
42 | { |
43 | assert(iter + 8 == sent1); |
44 | assert(iter + 8 == sent2); |
45 | assert(iter + 4 == sent4); |
46 | } |
47 | |
48 | { |
49 | assert(sent1 - iter == 8); |
50 | assert(sent4 - iter == 4); |
51 | assert(iter - sent1 == -8); |
52 | assert(iter - sent4 == -4); |
53 | } |
54 | |
55 | return true; |
56 | } |
57 | |
58 | int main(int, char**) { |
59 | test(); |
60 | static_assert(test()); |
61 | |
62 | return 0; |
63 | } |
64 | |