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 | // friend constexpr decltype(auto) iter_move(const iterator& i); |
12 | |
13 | #include <cassert> |
14 | #include <ranges> |
15 | |
16 | #include "../types.h" |
17 | |
18 | constexpr bool test() { |
19 | int buffer[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; |
20 | |
21 | { |
22 | std::ranges::join_view jv(buffer); |
23 | assert(std::ranges::iter_move(jv.begin()) == 1); |
24 | static_assert(std::is_same_v<decltype(std::ranges::iter_move(jv.begin())), int&&>); |
25 | |
26 | static_assert(noexcept(std::ranges::iter_move(std::declval<decltype(jv.begin())>()))); |
27 | } |
28 | |
29 | { |
30 | // iter_move calls inner's iter_move and calls |
31 | // iter_move on the correct inner iterator |
32 | IterMoveSwapAwareView inners[2] = {buffer[0], buffer[1]}; |
33 | std::ranges::join_view jv(inners); |
34 | auto it = jv.begin(); |
35 | |
36 | const auto& iter_move_called_times1 = jv.base().begin()->iter_move_called; |
37 | const auto& iter_move_called_times2 = std::next(jv.base().begin())->iter_move_called; |
38 | assert(iter_move_called_times1 == 0); |
39 | assert(iter_move_called_times2 == 0); |
40 | |
41 | std::same_as<std::pair<int&&, int&&>> decltype(auto) x = std::ranges::iter_move(it); |
42 | assert(std::get<0>(x) == 1); |
43 | assert(iter_move_called_times1 == 1); |
44 | assert(iter_move_called_times2 == 0); |
45 | |
46 | auto it2 = std::ranges::next(it, 4); |
47 | |
48 | std::same_as<std::pair<int&&, int&&>> decltype(auto) y = std::ranges::iter_move(it2); |
49 | assert(std::get<0>(y) == 5); |
50 | assert(iter_move_called_times1 == 1); |
51 | assert(iter_move_called_times2 == 1); |
52 | } |
53 | return true; |
54 | } |
55 | |
56 | int main(int, char**) { |
57 | test(); |
58 | static_assert(test()); |
59 | |
60 | return 0; |
61 | } |
62 | |