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 // constexpr counted_iterator& operator-=(iter_difference_t<I> n) 14 // requires random_access_iterator<I>; 15 16 #include <iterator> 17 18 #include "test_macros.h" 19 #include "test_iterators.h" 20 21 template<class Iter> 22 concept MinusEqEnabled = requires(Iter& iter) { 23 iter -= 1; 24 }; 25 26 constexpr bool test() { 27 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 28 29 { 30 using Counted = std::counted_iterator<random_access_iterator<int*>>; 31 Counted iter(random_access_iterator<int*>{buffer + 2}, 6); 32 assert((iter -= 2) == Counted(random_access_iterator<int*>{buffer}, 8)); 33 assert((iter -= 0) == Counted(random_access_iterator<int*>{buffer}, 8)); 34 assert(iter.count() == 8); 35 36 ASSERT_SAME_TYPE(decltype(iter -= 2), Counted&); 37 } 38 { 39 using Counted = std::counted_iterator<contiguous_iterator<int*>>; 40 Counted iter(contiguous_iterator<int*>{buffer + 2}, 6); 41 assert((iter -= 2) == Counted(contiguous_iterator<int*>{buffer}, 8)); 42 assert((iter -= 0) == Counted(contiguous_iterator<int*>{buffer}, 8)); 43 assert(iter.count() == 8); 44 45 ASSERT_SAME_TYPE(decltype(iter -= 2), Counted&); 46 } 47 { 48 static_assert( MinusEqEnabled< std::counted_iterator<random_access_iterator<int*>>>); 49 static_assert(!MinusEqEnabled<const std::counted_iterator<random_access_iterator<int*>>>); 50 } 51 52 53 return true; 54 } 55 56 int main(int, char**) { 57 test(); 58 static_assert(test()); 59 60 return 0; 61 } 62