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 // sentinel() = default; 14 // constexpr explicit sentinel(sentinel_t<Base> end); 15 // constexpr sentinel(sentinel<!Const> s) 16 // requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>; 17 18 #include <ranges> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 #include "../types.h" 24 25 constexpr bool test() { 26 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 27 28 { 29 // Test the default ctor. 30 std::ranges::take_view<MoveOnlyView> tv(MoveOnlyView{buffer}, 4); 31 assert(decltype(tv.end()){} == std::ranges::next(tv.begin(), 4)); 32 } 33 34 { 35 std::ranges::take_view<MoveOnlyView> nonConst(MoveOnlyView{buffer}, 5); 36 const std::ranges::take_view<MoveOnlyView> tvConst(MoveOnlyView{buffer}, 5); 37 auto sent1 = nonConst.end(); 38 // Convert to const. Note, we cannot go the other way. 39 std::remove_cv_t<decltype(tvConst.end())> sent2 = sent1; 40 41 assert(sent1 == std::ranges::next(tvConst.begin(), 5)); 42 assert(sent2 == std::ranges::next(tvConst.begin(), 5)); 43 } 44 45 { 46 std::ranges::take_view<CopyableView> tv(CopyableView{buffer}, 6); 47 auto sw = sentinel_wrapper<int *>(buffer + 6); 48 using Sent = decltype(tv.end()); 49 Sent sent = Sent(sw); 50 assert(sent.base().base() == sw.base()); 51 } 52 53 return true; 54 } 55 56 int main(int, char**) { 57 test(); 58 static_assert(test()); 59 60 return 0; 61 } 62