Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / counted.iterator / plus.pass.cpp
bloba397a8717b89a28e08050b748d15118ee312ee49
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // constexpr counted_iterator operator+(iter_difference_t<I> n) const
12 // requires random_access_iterator<I>;
13 // friend constexpr counted_iterator operator+(
14 // iter_difference_t<I> n, const counted_iterator& x)
15 // requires random_access_iterator<I>;
16 // constexpr counted_iterator& operator+=(iter_difference_t<I> n)
17 // requires random_access_iterator<I>;
19 #include <iterator>
21 #include "test_macros.h"
22 #include "test_iterators.h"
24 template<class Iter>
25 concept PlusEnabled = requires(Iter& iter) {
26 iter + 1;
29 template<class Iter>
30 concept PlusEqEnabled = requires(Iter& iter) {
31 iter += 1;
34 constexpr bool test() {
35 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
39 using Counted = std::counted_iterator<random_access_iterator<int*>>;
40 std::counted_iterator iter(random_access_iterator<int*>{buffer}, 8);
41 assert(iter + 2 == Counted(random_access_iterator<int*>{buffer + 2}, 6));
42 assert(iter + 0 == Counted(random_access_iterator<int*>{buffer}, 8));
44 ASSERT_SAME_TYPE(decltype(iter + 2), Counted);
47 using Counted = const std::counted_iterator<random_access_iterator<int*>>;
48 const std::counted_iterator iter(random_access_iterator<int*>{buffer}, 8);
49 assert(iter + 8 == Counted(random_access_iterator<int*>{buffer + 8}, 0));
50 assert(iter + 0 == Counted(random_access_iterator<int*>{buffer}, 8));
52 ASSERT_SAME_TYPE(decltype(iter + 2), std::remove_const_t<Counted>);
58 using Counted = std::counted_iterator<random_access_iterator<int*>>;
59 std::counted_iterator iter(random_access_iterator<int*>{buffer}, 8);
60 assert(2 + iter == Counted(random_access_iterator<int*>{buffer + 2}, 6));
61 assert(0 + iter == Counted(random_access_iterator<int*>{buffer}, 8));
63 ASSERT_SAME_TYPE(decltype(iter + 2), Counted);
66 using Counted = const std::counted_iterator<random_access_iterator<int*>>;
67 const std::counted_iterator iter(random_access_iterator<int*>{buffer}, 8);
68 assert(8 + iter == Counted(random_access_iterator<int*>{buffer + 8}, 0));
69 assert(0 + iter == Counted(random_access_iterator<int*>{buffer}, 8));
71 ASSERT_SAME_TYPE(decltype(iter + 2), std::remove_const_t<Counted>);
77 using Counted = std::counted_iterator<random_access_iterator<int*>>;
78 std::counted_iterator iter(random_access_iterator<int*>{buffer}, 8);
79 assert((iter += 2) == Counted(random_access_iterator<int*>{buffer + 2}, 6));
80 assert((iter += 0) == Counted(random_access_iterator<int*>{buffer + 2}, 6));
82 ASSERT_SAME_TYPE(decltype(iter += 2), Counted&);
85 using Counted = std::counted_iterator<contiguous_iterator<int*>>;
86 std::counted_iterator iter(contiguous_iterator<int*>{buffer}, 8);
87 assert((iter += 8) == Counted(contiguous_iterator<int*>{buffer + 8}, 0));
88 assert((iter += 0) == Counted(contiguous_iterator<int*>{buffer + 8}, 0));
90 ASSERT_SAME_TYPE(decltype(iter += 2), Counted&);
93 static_assert( PlusEnabled<std::counted_iterator<random_access_iterator<int*>>>);
94 static_assert(!PlusEnabled<std::counted_iterator<bidirectional_iterator<int*>>>);
96 static_assert( PlusEqEnabled< std::counted_iterator<random_access_iterator<int*>>>);
97 static_assert(!PlusEqEnabled<const std::counted_iterator<random_access_iterator<int*>>>);
101 return true;
104 int main(int, char**) {
105 test();
106 static_assert(test());
108 return 0;