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 // friend constexpr iter_difference_t<I> operator-(
12 // const counted_iterator& x, default_sentinel_t);
13 // friend constexpr iter_difference_t<I> operator-(
14 // default_sentinel_t, const counted_iterator& y);
18 #include "test_macros.h"
19 #include "test_iterators.h"
21 constexpr bool test() {
22 int buffer
[8] = {1, 2, 3, 4, 5, 6, 7, 8};
25 std::counted_iterator
iter(random_access_iterator
<int*>{buffer
}, 8);
26 assert(iter
- std::default_sentinel
== -8);
27 assert(std::default_sentinel
- iter
== 8);
28 assert(iter
.count() == 8);
30 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
31 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
34 const std::counted_iterator
iter(random_access_iterator
<int*>{buffer
}, 8);
35 assert(iter
- std::default_sentinel
== -8);
36 assert(std::default_sentinel
- iter
== 8);
37 assert(iter
.count() == 8);
39 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
40 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
43 std::counted_iterator
iter(forward_iterator
<int*>{buffer
}, 8);
44 assert(iter
- std::default_sentinel
== -8);
45 assert(std::default_sentinel
- iter
== 8);
46 assert(iter
.count() == 8);
48 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
49 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
52 const std::counted_iterator
iter(forward_iterator
<int*>{buffer
}, 8);
53 assert(iter
- std::default_sentinel
== -8);
54 assert(std::default_sentinel
- iter
== 8);
55 assert(iter
.count() == 8);
57 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
58 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
61 std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
62 assert(iter
- std::default_sentinel
== -8);
63 assert(std::default_sentinel
- iter
== 8);
64 assert(iter
.count() == 8);
66 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
67 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
70 const std::counted_iterator
iter(cpp20_input_iterator
<int*>{buffer
}, 8);
71 assert(iter
- std::default_sentinel
== -8);
72 assert(std::default_sentinel
- iter
== 8);
73 assert(iter
.count() == 8);
75 ASSERT_SAME_TYPE(decltype(iter
- std::default_sentinel
), std::iter_difference_t
<int*>);
76 ASSERT_SAME_TYPE(decltype(std::default_sentinel
- iter
), std::iter_difference_t
<int*>);
82 int main(int, char**) {
84 static_assert(test());