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
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);
15
16#include <iterator>
17
18#include "test_macros.h"
19#include "test_iterators.h"
20
21constexpr bool test() {
22 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
23
24 {
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);
29
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*>);
32 }
33 {
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);
38
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*>);
41 }
42 {
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);
47
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*>);
50 }
51 {
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);
56
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*>);
59 }
60 {
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);
65
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*>);
68 }
69 {
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);
74
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*>);
77 }
78
79 return true;
80}
81
82int main(int, char**) {
83 test();
84 static_assert(test());
85
86 return 0;
87}
88

source code of libcxx/test/std/iterators/predef.iterators/counted.iterator/minus.default_sentinel.pass.cpp