| 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 | // REQUIRES: std-at-least-c++23 |
| 10 | |
| 11 | // <ranges> |
| 12 | |
| 13 | // constexpr sentinel(sentinel<!Const> s) |
| 14 | // requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>; |
| 15 | |
| 16 | #include <ranges> |
| 17 | |
| 18 | #include <type_traits> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "../types.h" |
| 22 | #include "test_iterators.h" |
| 23 | |
| 24 | constexpr bool test() { |
| 25 | { // Regular conversion from `!Const` to `Const` sentinel |
| 26 | using Inner = BasicVectorView<int, ViewProperties{.common = false}, forward_iterator>; |
| 27 | std::vector<Inner> vec = {Inner{11, 12}, Inner{13, 14}}; |
| 28 | |
| 29 | std::ranges::join_with_view jwv(vec, 0); |
| 30 | using JWV = decltype(jwv); |
| 31 | static_assert(!std::ranges::common_range<JWV>); |
| 32 | |
| 33 | using Sent = std::ranges::sentinel_t<JWV>; |
| 34 | using CSent = std::ranges::sentinel_t<const JWV>; |
| 35 | static_assert(!std::same_as<Sent, CSent>); |
| 36 | |
| 37 | Sent se = jwv.end(); |
| 38 | [[maybe_unused]] CSent cse = se; |
| 39 | } |
| 40 | |
| 41 | { // Test conversion from `Const` to `!Const` (should be invalid) |
| 42 | using Inner = BasicVectorView<int, ViewProperties{.common = false}, forward_iterator>; |
| 43 | using V = std::vector<Inner>; |
| 44 | using Pattern = std::ranges::single_view<int>; |
| 45 | using JWV = std::ranges::join_with_view<std::views::all_t<V>, Pattern>; |
| 46 | static_assert(!std::ranges::common_range<JWV>); |
| 47 | |
| 48 | using Sent = std::ranges::sentinel_t<JWV>; |
| 49 | using CSent = std::ranges::sentinel_t<const JWV>; |
| 50 | static_assert(!std::convertible_to<CSent, Sent>); |
| 51 | static_assert(!std::constructible_from<Sent, CSent>); |
| 52 | } |
| 53 | |
| 54 | { // When `convertible_to<sentinel_t<V>, sentinel_t<Base>>` is not modeled |
| 55 | using V = ConstOppositeView<std::vector<long>>; |
| 56 | using Pattern = std::ranges::single_view<long>; |
| 57 | using JWV = std::ranges::join_with_view<V, Pattern>; |
| 58 | static_assert(!std::ranges::common_range<JWV>); |
| 59 | |
| 60 | using Sent = std::ranges::sentinel_t<JWV>; |
| 61 | using CSent = std::ranges::sentinel_t<const JWV>; |
| 62 | static_assert(!std::convertible_to<CSent, Sent>); |
| 63 | static_assert(!std::constructible_from<Sent, CSent>); |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | int main(int, char**) { |
| 70 | test(); |
| 71 | static_assert(test()); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |