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