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()
13 // requires sized_range<V>
14 // constexpr auto size() const
15 // requires sized_range<const V>
16
17 #include <ranges>
18
19 #include "test_macros.h"
20 #include "types.h"
21
22 template<class T>
23 concept SizeInvocable = requires(std::ranges::drop_view<T> t) { t.size(); };
24
test()25 constexpr bool test() {
26 // sized_range<V>
27 std::ranges::drop_view dropView1(MoveOnlyView(), 4);
28 assert(dropView1.size() == 4);
29
30 // sized_range<V>
31 std::ranges::drop_view dropView2(MoveOnlyView(), 0);
32 assert(dropView2.size() == 8);
33
34 // sized_range<const V>
35 const std::ranges::drop_view dropView3(MoveOnlyView(), 8);
36 assert(dropView3.size() == 0);
37
38 // sized_range<const V>
39 const std::ranges::drop_view dropView4(MoveOnlyView(), 10);
40 assert(dropView4.size() == 0);
41
42 // Because ForwardView is not a sized_range.
43 static_assert(!SizeInvocable<ForwardView>);
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