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