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