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