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 <cassert>
16 #include <ranges>
17
18 #include "test_macros.h"
19 #include "types.h"
20
hasLValueQualifiedBase(auto && view)21 constexpr bool hasLValueQualifiedBase(auto&& view) {
22 return requires { view.base(); };
23 }
24
test()25 constexpr bool test() {
26 int buffer[4][4] = {{1111, 2222, 3333, 4444}, {555, 666, 777, 888}, {99, 1010, 1111, 1212}, {13, 14, 15, 16}};
27
28 {
29 ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])};
30 auto jv = std::ranges::join_view(ParentView{children});
31 assert(std::move(jv).base().ptr_ == children);
32
33 static_assert(!hasLValueQualifiedBase(jv));
34 ASSERT_SAME_TYPE(decltype(std::move(jv).base()), ParentView<ChildView>);
35 }
36
37 {
38 std::ranges::join_view jv(buffer);
39 assert(jv.base().base() == buffer + 0);
40
41 static_assert(hasLValueQualifiedBase(jv));
42 ASSERT_SAME_TYPE(decltype(jv.base()), std::ranges::ref_view<int [4][4]>);
43 }
44
45 {
46 const std::ranges::join_view jv(buffer);
47 assert(jv.base().base() == buffer + 0);
48
49 static_assert(hasLValueQualifiedBase(jv));
50 ASSERT_SAME_TYPE(decltype(jv.base()), std::ranges::ref_view<int [4][4]>);
51 }
52
53 return true;
54 }
55
main(int,char **)56 int main(int, char**) {
57 test();
58 static_assert(test());
59
60 return 0;
61 }
62