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