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 explicit common_view(V r);
13
14 #include <ranges>
15
16 #include <cassert>
17 #include <utility>
18
19 #include "test_iterators.h"
20 #include "types.h"
21
test()22 constexpr bool test() {
23 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
24
25 {
26 MoveOnlyView view{buf, buf + 8};
27 std::ranges::common_view<MoveOnlyView> common(std::move(view));
28 assert(std::move(common).base().begin_ == buf);
29 }
30
31 {
32 CopyableView const view{buf, buf + 8};
33 std::ranges::common_view<CopyableView> const common(view);
34 assert(common.base().begin_ == buf);
35 }
36
37 return true;
38 }
39
main(int,char **)40 int main(int, char**) {
41 test();
42 static_assert(test());
43
44 // Can't compare common_iterator inside constexpr
45 {
46 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
47 MoveOnlyView view{buf, buf + 8};
48 std::ranges::common_view<MoveOnlyView> const common(std::move(view));
49 assert(common.begin() == buf);
50 }
51
52 return 0;
53 }
54