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