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: gcc-10 12 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 13 14 // constexpr auto end() requires (!simple-view<V>) 15 // constexpr auto end() const requires range<const V> 16 17 #include <ranges> 18 #include <cassert> 19 20 #include "test_macros.h" 21 #include "test_iterators.h" 22 #include "test_range.h" 23 #include "types.h" 24 25 constexpr bool test() { 26 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 27 28 // sized_range && random_access_iterator 29 { 30 std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView{buffer}, 0); 31 assert(tv.end() == std::ranges::next(tv.begin(), 0)); 32 ASSERT_SAME_TYPE(decltype(tv.end()), RandomAccessIter); 33 } 34 35 { 36 const std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView{buffer}, 1); 37 assert(tv.end() == std::ranges::next(tv.begin(), 1)); 38 ASSERT_SAME_TYPE(decltype(tv.end()), RandomAccessIter); 39 } 40 41 // sized_range && !random_access_iterator 42 { 43 std::ranges::take_view<SizedForwardView> tv(SizedForwardView{buffer}, 2); 44 assert(tv.end() == std::ranges::next(tv.begin(), 2)); 45 ASSERT_SAME_TYPE(decltype(tv.end()), std::default_sentinel_t); 46 } 47 48 { 49 const std::ranges::take_view<SizedForwardView> tv(SizedForwardView{buffer}, 3); 50 assert(tv.end() == std::ranges::next(tv.begin(), 3)); 51 ASSERT_SAME_TYPE(decltype(tv.end()), std::default_sentinel_t); 52 } 53 54 // !sized_range 55 { 56 std::ranges::take_view<ContiguousView> tv(ContiguousView{buffer}, 4); 57 assert(tv.end() == std::ranges::next(tv.begin(), 4)); 58 59 // The <sentinel> type. 60 static_assert(!std::same_as<decltype(tv.end()), std::default_sentinel_t>); 61 static_assert(!std::same_as<decltype(tv.end()), int*>); 62 } 63 64 { 65 const std::ranges::take_view<ContiguousView> tv(ContiguousView{buffer}, 5); 66 assert(tv.end() == std::ranges::next(tv.begin(), 5)); 67 } 68 69 // Just to cover the case where count == 8. 70 { 71 std::ranges::take_view<SizedRandomAccessView> tv(SizedRandomAccessView{buffer}, 8); 72 assert(tv.end() == std::ranges::next(tv.begin(), 8)); 73 } 74 75 return true; 76 } 77 78 int main(int, char**) { 79 test(); 80 static_assert(test()); 81 82 return 0; 83 } 84