| 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 |
|
| 11 |
// friend constexpr bool operator==(const iterator& x, const sentinel& y); |
| 12 |
|
| 13 |
#include <algorithm> |
| 14 |
#include <cassert> |
| 15 |
#include <concepts> |
| 16 |
#include <ranges> |
| 17 |
|
| 18 |
#include "test_iterators.h" |
| 19 |
|
| 20 |
template <class Iter> |
| 21 |
constexpr void testOne() { |
| 22 |
using Sent = sentinel_wrapper<Iter>; |
| 23 |
using Range = std::ranges::subrange<Iter, Sent>; |
| 24 |
using SplitView = std::ranges::split_view<Range, std::ranges::single_view<int>>; |
| 25 |
static_assert(!std::ranges::common_range<SplitView>); |
| 26 |
|
| 27 |
{ |
| 28 |
// simple test |
| 29 |
{ |
| 30 |
int buffer[] = {0, 1, 2, -1, 4, 5, 6}; |
| 31 |
Range input(Iter{buffer}, Sent{Iter{buffer + 7}}); |
| 32 |
SplitView sv(input, -1); |
| 33 |
auto b = sv.begin(); |
| 34 |
auto e = sv.end(); |
| 35 |
|
| 36 |
assert(!(b == e)); |
| 37 |
assert(b != e); |
| 38 |
|
| 39 |
std::advance(b, 2); |
| 40 |
assert(b == e); |
| 41 |
assert(!(b != e)); |
| 42 |
} |
| 43 |
|
| 44 |
// iterator at trailing empty position should not equal to end |
| 45 |
{ |
| 46 |
int buffer[] = {0, 1, 2, -1}; |
| 47 |
Range input(Iter{buffer}, Sent{Iter{buffer + 4}}); |
| 48 |
SplitView sv(input, -1); |
| 49 |
auto b = sv.begin(); |
| 50 |
auto e = sv.end(); |
| 51 |
|
| 52 |
++b; // cur points to end but trailing_empty is true |
| 53 |
|
| 54 |
assert(b != e); |
| 55 |
assert(!(b == e)); |
| 56 |
|
| 57 |
++b; |
| 58 |
assert(b == e); |
| 59 |
assert(!(b != e)); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
constexpr bool test() { |
| 65 |
testOne<forward_iterator<int*>>(); |
| 66 |
testOne<bidirectional_iterator<int*>>(); |
| 67 |
testOne<random_access_iterator<int*>>(); |
| 68 |
testOne<contiguous_iterator<int*>>(); |
| 69 |
testOne<int*>(); |
| 70 |
|
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
int main(int, char**) { |
| 75 |
test(); |
| 76 |
static_assert(test()); |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |