| 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 |
// template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2> |
| 12 |
// requires sized_sentinel_for<S, I2> |
| 13 |
// friend iter_difference_t<I2> operator-( |
| 14 |
// const common_iterator& x, const common_iterator<I2, S2>& y); |
| 15 |
|
| 16 |
#include <iterator> |
| 17 |
#include <cassert> |
| 18 |
|
| 19 |
#include "test_macros.h" |
| 20 |
#include "types.h" |
| 21 |
|
| 22 |
void test() { |
| 23 |
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
| 24 |
|
| 25 |
{ |
| 26 |
auto iter1 = random_access_iterator<int*>(buffer); |
| 27 |
auto commonIter1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(iter1); |
| 28 |
auto commonSent1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(sized_sentinel_type<int*>{buffer + 8}); |
| 29 |
assert(commonIter1 - commonSent1 == -8); |
| 30 |
assert(commonSent1 - commonIter1 == 8); |
| 31 |
assert(commonIter1 - commonIter1 == 0); |
| 32 |
assert(commonSent1 - commonSent1 == 0); |
| 33 |
} |
| 34 |
{ |
| 35 |
auto iter1 = simple_iterator<int*>(buffer); |
| 36 |
auto iter2 = comparable_iterator<int*>(buffer); |
| 37 |
auto commonIter1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(iter1); |
| 38 |
auto commonIter2 = std::common_iterator<decltype(iter2), sized_sentinel_type<int*>>(iter2); |
| 39 |
|
| 40 |
assert(commonIter1 - commonIter2 == 0); |
| 41 |
} |
| 42 |
{ |
| 43 |
auto iter1 = random_access_iterator<int*>(buffer); |
| 44 |
const auto commonIter1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(iter1); |
| 45 |
const auto commonSent1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(sized_sentinel_type<int*>{buffer + 8}); |
| 46 |
assert(commonIter1 - commonSent1 == -8); |
| 47 |
assert(commonSent1 - commonIter1 == 8); |
| 48 |
assert(commonIter1 - commonIter1 == 0); |
| 49 |
assert(commonSent1 - commonSent1 == 0); |
| 50 |
} |
| 51 |
{ |
| 52 |
auto iter1 = simple_iterator<int*>(buffer); |
| 53 |
auto iter2 = comparable_iterator<int*>(buffer); |
| 54 |
const auto commonIter1 = std::common_iterator<decltype(iter1), sized_sentinel_type<int*>>(iter1); |
| 55 |
const auto commonIter2 = std::common_iterator<decltype(iter2), sized_sentinel_type<int*>>(iter2); |
| 56 |
|
| 57 |
assert(commonIter1 - commonIter2 == 0); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
int main(int, char**) { |
| 62 |
test(); |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |