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