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--()
12 // requires bidirectional_iterator<I>;
13 // constexpr counted_iterator operator--(int)
14 // requires bidirectional_iterator<I>;
18 #include "test_macros.h"
19 #include "test_iterators.h"
22 concept MinusEnabled
= requires(Iter
& iter
) {
27 constexpr bool test() {
28 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
31 using Counted
= std::counted_iterator
<bidirectional_iterator
<int*>>;
32 std::counted_iterator
iter(bidirectional_iterator
<int*>{buffer
+ 2}, 6);
33 assert(iter
-- == Counted(bidirectional_iterator
<int*>{buffer
+ 2}, 6));
34 assert(--iter
== Counted(bidirectional_iterator
<int*>{buffer
}, 8));
35 assert(iter
.count() == 8);
37 ASSERT_SAME_TYPE(decltype(iter
--), Counted
);
38 ASSERT_SAME_TYPE(decltype(--iter
), Counted
&);
41 using Counted
= std::counted_iterator
<random_access_iterator
<int*>>;
42 Counted
iter(random_access_iterator
<int*>{buffer
+ 2}, 6);
43 assert(iter
-- == Counted(random_access_iterator
<int*>{buffer
+ 2}, 6));
44 assert(--iter
== Counted(random_access_iterator
<int*>{buffer
}, 8));
45 assert(iter
.count() == 8);
47 ASSERT_SAME_TYPE(decltype(iter
--), Counted
);
48 ASSERT_SAME_TYPE(decltype(--iter
), Counted
&);
51 using Counted
= std::counted_iterator
<contiguous_iterator
<int*>>;
52 std::counted_iterator
iter(contiguous_iterator
<int*>{buffer
+ 2}, 6);
53 assert(iter
-- == Counted(contiguous_iterator
<int*>{buffer
+ 2}, 6));
54 assert(--iter
== Counted(contiguous_iterator
<int*>{buffer
}, 8));
55 assert(iter
.count() == 8);
57 ASSERT_SAME_TYPE(decltype(iter
--), Counted
);
58 ASSERT_SAME_TYPE(decltype(--iter
), Counted
&);
62 static_assert( MinusEnabled
<std::counted_iterator
<contiguous_iterator
<int*>>>);
63 static_assert(!MinusEnabled
<const std::counted_iterator
<contiguous_iterator
<int*>>>);
64 static_assert(!MinusEnabled
<std::counted_iterator
<forward_iterator
<int*>>>);
70 int main(int, char**) {
72 static_assert(test());