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