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