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 | // transform_view::<iterator>::operator* |
12 | |
13 | #include <ranges> |
14 | |
15 | #include "test_macros.h" |
16 | #include "../types.h" |
17 | |
18 | int main(int, char**) { |
19 | { |
20 | int buff[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
21 | using View = std::ranges::transform_view<MoveOnlyView, PlusOne>; |
22 | View transformView(MoveOnlyView{buff}, PlusOne{}); |
23 | assert(*transformView.begin() == 1); |
24 | ASSERT_NOT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>()); |
25 | ASSERT_SAME_TYPE(int, decltype(*std::declval<View>().begin())); |
26 | } |
27 | { |
28 | int buff[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
29 | using View = std::ranges::transform_view<MoveOnlyView, PlusOneMutable>; |
30 | View transformView(MoveOnlyView{buff}, PlusOneMutable{}); |
31 | assert(*transformView.begin() == 1); |
32 | ASSERT_NOT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>()); |
33 | ASSERT_SAME_TYPE(int, decltype(*std::declval<View>().begin())); |
34 | } |
35 | { |
36 | int buff[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
37 | using View = std::ranges::transform_view<MoveOnlyView, PlusOneNoexcept>; |
38 | View transformView(MoveOnlyView{buff}, PlusOneNoexcept{}); |
39 | assert(*transformView.begin() == 1); |
40 | LIBCPP_ASSERT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>()); |
41 | ASSERT_SAME_TYPE(int, decltype(*std::declval<View>().begin())); |
42 | } |
43 | { |
44 | int buff[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
45 | using View = std::ranges::transform_view<MoveOnlyView, Increment>; |
46 | View transformView(MoveOnlyView{buff}, Increment{}); |
47 | assert(*transformView.begin() == 1); |
48 | ASSERT_NOT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>()); |
49 | ASSERT_SAME_TYPE(int&, decltype(*std::declval<View>().begin())); |
50 | } |
51 | { |
52 | int buff[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
53 | using View = std::ranges::transform_view<MoveOnlyView, IncrementRvalueRef>; |
54 | View transformView(MoveOnlyView{buff}, IncrementRvalueRef{}); |
55 | assert(*transformView.begin() == 1); |
56 | ASSERT_NOT_NOEXCEPT(*std::declval<std::ranges::iterator_t<View>>()); |
57 | ASSERT_SAME_TYPE(int&&, decltype(*std::declval<View>().begin())); |
58 | } |
59 | |
60 | return 0; |
61 | } |
62 | |