//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // REQUIRES: std-at-least-c++23 // // template // requires sentinel_for, iterator_t>> // friend constexpr bool operator==(const iterator& x, const sentinel& y); #include #include #include #include #include #include "../types.h" #include "test_comparisons.h" #include "test_iterators.h" struct NonCrossConstComparableView : std::ranges::view_base { using NonConstRange = std::vector; NonConstRange* begin(); sentinel_wrapper end(); using ConstRange = BasicVectorView; ConstRange* begin() const; sentinel_wrapper end() const; }; static_assert(std::ranges::range); static_assert(std::ranges::range); constexpr bool test() { using Inner = BasicVectorView; using V = std::vector; using Pattern = std::ranges::single_view; using JWV = std::ranges::join_with_view, Pattern>; static_assert(!std::ranges::common_range); using Iter = std::ranges::iterator_t; using CIter = std::ranges::iterator_t; static_assert(!std::same_as); using Sent = std::ranges::sentinel_t; using CSent = std::ranges::sentinel_t; static_assert(!std::same_as); { // Compare iterator with sentinel { // Const == true AssertEqualityReturnBool(); const JWV jwv(V{Inner{1, 2}, Inner{4}}, 3); assert(testEquality(std::ranges::next(jwv.begin(), 4), jwv.end(), true)); assert(testEquality(jwv.begin(), jwv.end(), false)); } { // Const == false AssertEqualityReturnBool(); JWV jwv(V{Inner{5}, Inner{7, 8}}, 6); assert(testEquality(std::ranges::next(jwv.begin(), 4), jwv.end(), true)); assert(testEquality(std::ranges::next(jwv.begin(), 2), jwv.end(), false)); } } { // Compare iterator with sentinel { // Const == true AssertEqualityReturnBool(); JWV jwv(V{Inner{9, 10}, Inner{12}}, 11); assert(testEquality(std::ranges::next(std::as_const(jwv).begin(), 4), jwv.end(), true)); assert(testEquality(std::ranges::next(std::as_const(jwv).begin(), 2), jwv.end(), false)); } { // Const == false AssertEqualityReturnBool(); JWV jwv(V{Inner{13}, Inner{15, 16}}, 14); assert(testEquality(std::ranges::next(jwv.begin(), 4), std::as_const(jwv).end(), true)); assert(testEquality(std::ranges::next(jwv.begin(), 3), std::as_const(jwv).end(), false)); } } { // Check invalid comparisons between iterator and sentinel using JWV2 = std::ranges::join_with_view; static_assert(!std::ranges::common_range); static_assert(!weakly_equality_comparable_with, std::ranges::sentinel_t>); static_assert(!weakly_equality_comparable_with, std::ranges::sentinel_t>); // Those should be valid static_assert(weakly_equality_comparable_with, std::ranges::sentinel_t>); static_assert( weakly_equality_comparable_with, std::ranges::sentinel_t>); } return true; } int main(int, char**) { test(); static_assert(test()); return 0; }