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 using TakeView = std::ranges::take_view<MoveOnlyView>; 31 using Sentinel = std::ranges::sentinel_t<TakeView>; 32 Sentinel s; 33 TakeView tv = TakeView(MoveOnlyView(buffer), 4); 34 assert(tv.begin() + 4 == s); 35 } 36 37 { 38 // Test the conversion from "sentinel" to "sentinel-to-const". 39 using TakeView = std::ranges::take_view<MoveOnlyView>; 40 using Sentinel = std::ranges::sentinel_t<TakeView>; 41 using ConstSentinel = std::ranges::sentinel_t<const TakeView>; 42 static_assert(std::is_convertible_v<Sentinel, ConstSentinel>); 43 TakeView tv = TakeView(MoveOnlyView(buffer), 4); 44 Sentinel s = tv.end(); 45 ConstSentinel cs = s; 46 cs = s; // test assignment also 47 assert(tv.begin() + 4 == s); 48 assert(tv.begin() + 4 == cs); 49 assert(std::as_const(tv).begin() + 4 == s); 50 assert(std::as_const(tv).begin() + 4 == cs); 51 } 52 53 { 54 // Test the constructor from "base-sentinel" to "sentinel". 55 using TakeView = std::ranges::take_view<MoveOnlyView>; 56 using Sentinel = std::ranges::sentinel_t<TakeView>; 57 sentinel_wrapper<int*> sw1 = MoveOnlyView(buffer).end(); 58 static_assert( std::is_constructible_v<Sentinel, sentinel_wrapper<int*>>); 59 static_assert(!std::is_convertible_v<sentinel_wrapper<int*>, Sentinel>); 60 auto s = Sentinel(sw1); 61 std::same_as<sentinel_wrapper<int*>> auto sw2 = s.base(); 62 assert(base(sw2) == base(sw1)); 63 } 64 65 return true; 66 } 67 68 int main(int, char**) { 69 test(); 70 static_assert(test()); 71 72 return 0; 73 } 74