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