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
18constexpr bool test() {
19 int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
20 std::ranges::transform_view transformView1(MoveOnlyView{buff}, PlusOneMutable{});
21 auto iter1 = std::move(transformView1).begin() + 1;
22 assert(iter1[0] == 2);
23 assert(iter1[4] == 6);
24
25 ASSERT_NOT_NOEXCEPT(
26 std::declval<std::ranges::iterator_t<std::ranges::transform_view<MoveOnlyView, PlusOneMutable>>>()[0]);
27 LIBCPP_ASSERT_NOEXCEPT(
28 std::declval<std::ranges::iterator_t<std::ranges::transform_view<MoveOnlyView, PlusOneNoexcept>>>()[0]);
29
30 ASSERT_SAME_TYPE(
31 int,
32 decltype(std::declval<std::ranges::transform_view<RandomAccessView, PlusOneMutable>>().begin()[0]));
33 ASSERT_SAME_TYPE(
34 int&,
35 decltype(std::declval<std::ranges::transform_view<RandomAccessView, Increment>>().begin()[0]));
36 ASSERT_SAME_TYPE(
37 int&&,
38 decltype(std::declval<std::ranges::transform_view<RandomAccessView, IncrementRvalueRef>>().begin()[0]));
39
40 return true;
41}
42
43int main(int, char**) {
44 test();
45 static_assert(test());
46
47 return 0;
48}
49

source code of libcxx/test/std/ranges/range.adaptors/range.transform/iterator/subscript.pass.cpp