1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr counted_iterator& operator-=(iter_difference_t<I> n)
12 // requires random_access_iterator<I>;
16 #include "test_macros.h"
17 #include "test_iterators.h"
20 concept MinusEqEnabled
= requires(Iter
& iter
) {
24 constexpr bool test() {
25 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
28 using Counted
= std::counted_iterator
<random_access_iterator
<int*>>;
29 Counted
iter(random_access_iterator
<int*>{buffer
+ 2}, 6);
30 assert((iter
-= 2) == Counted(random_access_iterator
<int*>{buffer
}, 8));
31 assert((iter
-= 0) == Counted(random_access_iterator
<int*>{buffer
}, 8));
32 assert(iter
.count() == 8);
34 ASSERT_SAME_TYPE(decltype(iter
-= 2), Counted
&);
37 using Counted
= std::counted_iterator
<contiguous_iterator
<int*>>;
38 Counted
iter(contiguous_iterator
<int*>{buffer
+ 2}, 6);
39 assert((iter
-= 2) == Counted(contiguous_iterator
<int*>{buffer
}, 8));
40 assert((iter
-= 0) == Counted(contiguous_iterator
<int*>{buffer
}, 8));
41 assert(iter
.count() == 8);
43 ASSERT_SAME_TYPE(decltype(iter
-= 2), Counted
&);
46 static_assert( MinusEqEnabled
< std::counted_iterator
<random_access_iterator
<int*>>>);
47 static_assert(!MinusEqEnabled
<const std::counted_iterator
<random_access_iterator
<int*>>>);
54 int main(int, char**) {
56 static_assert(test());