[TableGen] Add TreePatternNode::children and use it in for loops (NFC) (#119877)
[llvm-project.git] / libcxx / test / std / iterators / iterator.primitives / iterator.operations / prev.pass.cpp
blob784c1b93b7ca893f76dd770f4edeb5bdcedb2daa
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 // <iterator>
11 // template <InputIterator Iter>
12 // Iter prev(Iter x, Iter::difference_type n = 1); // constexpr in C++17
14 #include <iterator>
15 #include <cassert>
16 #include <type_traits>
18 #include "test_macros.h"
19 #include "test_iterators.h"
21 template <class It>
22 TEST_CONSTEXPR_CXX17 void
23 check_prev_n(It it, typename std::iterator_traits<It>::difference_type n, It result)
25 static_assert(std::is_same<decltype(std::prev(it, n)), It>::value, "");
26 assert(std::prev(it, n) == result);
28 It (*prev_ptr)(It, typename std::iterator_traits<It>::difference_type) = std::prev;
29 assert(prev_ptr(it, n) == result);
32 template <class It>
33 TEST_CONSTEXPR_CXX17 void
34 check_prev_1(It it, It result)
36 static_assert(std::is_same<decltype(std::prev(it)), It>::value, "");
37 assert(std::prev(it) == result);
40 TEST_CONSTEXPR_CXX17 bool tests()
42 const char* s = "1234567890";
43 check_prev_n(forward_iterator <const char*>(s), -10, forward_iterator <const char*>(s+10));
44 check_prev_n(bidirectional_iterator<const char*>(s+10), 10, bidirectional_iterator<const char*>(s));
45 check_prev_n(bidirectional_iterator<const char*>(s), -10, bidirectional_iterator<const char*>(s+10));
46 check_prev_n(random_access_iterator<const char*>(s+10), 10, random_access_iterator<const char*>(s));
47 check_prev_n(random_access_iterator<const char*>(s), -10, random_access_iterator<const char*>(s+10));
48 check_prev_n(s+10, 10, s);
50 check_prev_1(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
51 check_prev_1(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
52 check_prev_1(s+1, s);
54 return true;
57 int main(int, char**)
59 tests();
60 #if TEST_STD_VER >= 17
61 static_assert(tests(), "");
62 #endif
63 return 0;