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