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