Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / counted.iterator / minus.eq.pass.cpp
blob854c36a8c35be22dc74dd0391d849e8005676a93
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)
12 // requires random_access_iterator<I>;
14 #include <iterator>
16 #include "test_macros.h"
17 #include "test_iterators.h"
19 template<class Iter>
20 concept MinusEqEnabled = requires(Iter& iter) {
21 iter -= 1;
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*>>>);
51 return true;
54 int main(int, char**) {
55 test();
56 static_assert(test());
58 return 0;