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: gcc-10
12 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
13 
14 // constexpr auto size()
15 //   requires sized_range<V>
16 // constexpr auto size() const
17 //   requires sized_range<const V>
18 
19 #include <ranges>
20 
21 #include "test_macros.h"
22 #include "types.h"
23 
24 template<class T>
25 concept SizeInvocable = requires(std::ranges::drop_view<T> t) { t.size(); };
26 
27 constexpr bool test() {
28   // sized_range<V>
29   std::ranges::drop_view dropView1(ContiguousView(), 4);
30   assert(dropView1.size() == 4);
31 
32   // sized_range<V>
33   std::ranges::drop_view dropView2(ContiguousView(), 0);
34   assert(dropView2.size() == 8);
35 
36   // sized_range<const V>
37   const std::ranges::drop_view dropView3(ContiguousView(), 8);
38   assert(dropView3.size() == 0);
39 
40   // sized_range<const V>
41   const std::ranges::drop_view dropView4(ContiguousView(), 10);
42   assert(dropView4.size() == 0);
43 
44   // Because ForwardView is not a sized_range.
45   static_assert(!SizeInvocable<ForwardView>);
46 
47   return true;
48 }
49 
50 int main(int, char**) {
51   test();
52   static_assert(test());
53 
54   return 0;
55 }
56