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 auto size() requires sized_range<V>
13 // constexpr auto size() const requires sized_range<const V>
14
15 #include <ranges>
16 #include <cassert>
17
18 #include "test_iterators.h"
19 #include "types.h"
20
21 template<class View>
22 concept SizeEnabled = requires(View v) { v.size(); };
23
test()24 constexpr bool test() {
25 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
26
27 {
28 static_assert( SizeEnabled<std::ranges::common_view<SizedForwardView> const&>);
29 static_assert(!SizeEnabled<std::ranges::common_view<CopyableView> const&>);
30 }
31
32 {
33 SizedForwardView view{buf, buf + 8};
34 std::ranges::common_view<SizedForwardView> common(view);
35 assert(common.size() == 8);
36 }
37
38 {
39 SizedForwardView view{buf, buf + 8};
40 std::ranges::common_view<SizedForwardView> const common(view);
41 assert(common.size() == 8);
42 }
43
44 return true;
45 }
46
main(int,char **)47 int main(int, char**) {
48 test();
49 static_assert(test());
50
51 return 0;
52 }
53