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// constexpr iterator_t<V> base() const;
12
13#include <cassert>
14#include <ranges>
15
16#include "../types.h"
17
18struct Iter : ForwardIterBase<Iter> {
19 int i;
20 constexpr Iter() = default;
21 constexpr Iter(int ii) : i(ii) {}
22};
23
24constexpr bool test() {
25 // base only has one const overload
26 using SplitView = std::ranges::split_view<std::ranges::subrange<Iter>, std::ranges::subrange<Iter>>;
27 using SplitIter = std::ranges::iterator_t<SplitView>;
28
29 // const &
30 {
31 SplitView sv;
32 const SplitIter it{sv, Iter{5}, {}};
33 std::same_as<Iter> decltype(auto) base = it.base();
34 assert(base.i == 5);
35 }
36
37 // &
38 {
39 SplitView sv;
40 SplitIter it{sv, Iter{5}, {}};
41 std::same_as<Iter> decltype(auto) base = it.base();
42 assert(base.i == 5);
43 }
44
45 // &&
46 {
47 SplitView sv;
48 SplitIter it{sv, Iter{5}, {}};
49 std::same_as<Iter> decltype(auto) base = std::move(it).base();
50 assert(base.i == 5);
51 }
52
53 // const &&
54 {
55 SplitView sv;
56 const SplitIter it{sv, Iter{5}, {}};
57 std::same_as<Iter> decltype(auto) base = std::move(it).base();
58 assert(base.i == 5);
59 }
60
61 return true;
62}
63
64int main(int, char**) {
65 test();
66 static_assert(test());
67
68 return 0;
69}
70

source code of libcxx/test/std/ranges/range.adaptors/range.split/iterator/base.pass.cpp