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 V base() const& requires copy_constructible<V>;
12// constexpr V base() &&;
13
14#include <ranges>
15#include <cassert>
16
17#include "test_macros.h"
18#include "test_iterators.h"
19#include "types.h"
20
21constexpr bool hasLValueQualifiedBase(auto&& view) {
22 return requires { view.base(); };
23}
24
25constexpr bool test() {
26 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
27
28 {
29 std::ranges::take_view<CopyableView> tv(CopyableView{buffer}, 0);
30 assert(tv.base().ptr_ == buffer);
31 assert(std::move(tv).base().ptr_ == buffer);
32
33 ASSERT_SAME_TYPE(decltype(tv.base()), CopyableView);
34 ASSERT_SAME_TYPE(decltype(std::move(tv).base()), CopyableView);
35 static_assert(hasLValueQualifiedBase(tv));
36 }
37
38 {
39 std::ranges::take_view<MoveOnlyView> tv(MoveOnlyView{buffer}, 1);
40 assert(std::move(tv).base().ptr_ == buffer);
41
42 ASSERT_SAME_TYPE(decltype(std::move(tv).base()), MoveOnlyView);
43 static_assert(!hasLValueQualifiedBase(tv));
44 }
45
46 {
47 const std::ranges::take_view<CopyableView> tv(CopyableView{buffer}, 2);
48 assert(tv.base().ptr_ == buffer);
49 assert(std::move(tv).base().ptr_ == buffer);
50
51 ASSERT_SAME_TYPE(decltype(tv.base()), CopyableView);
52 ASSERT_SAME_TYPE(decltype(std::move(tv).base()), CopyableView);
53 static_assert(hasLValueQualifiedBase(tv));
54 }
55
56 return true;
57}
58
59int main(int, char**) {
60 test();
61 static_assert(test());
62
63 return 0;
64}
65

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