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