AMDGPU: Fix verifier assert with out of bounds subregister indexes (#119799)
[llvm-project.git] / libcxx / test / std / iterators / iterator.primitives / iterator.operations / next.pass.cpp
blobbc34e75d818ae53251fc1c7258c52e6edccf441f
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 next(Iter x, Iter::difference_type n = 1); // constexpr in C++17
14 // LWG #2353 relaxed the requirement on next from ForwardIterator to InputIterator
16 #include <iterator>
17 #include <cassert>
18 #include <type_traits>
20 #include "test_macros.h"
21 #include "test_iterators.h"
23 template <class It>
24 TEST_CONSTEXPR_CXX17 void
25 check_next_n(It it, typename std::iterator_traits<It>::difference_type n, It result)
27 static_assert(std::is_same<decltype(std::next(it, n)), It>::value, "");
28 assert(std::next(it, n) == result);
30 It (*next_ptr)(It, typename std::iterator_traits<It>::difference_type) = std::next;
31 assert(next_ptr(it, n) == result);
34 template <class It>
35 TEST_CONSTEXPR_CXX17 void
36 check_next_1(It it, It result)
38 static_assert(std::is_same<decltype(std::next(it)), It>::value, "");
39 assert(std::next(it) == result);
42 TEST_CONSTEXPR_CXX17 bool tests()
44 const char* s = "1234567890";
45 check_next_n(cpp17_input_iterator<const char*>(s), 10, cpp17_input_iterator<const char*>(s+10));
46 check_next_n(forward_iterator<const char*>(s), 10, forward_iterator<const char*>(s+10));
47 check_next_n(bidirectional_iterator<const char*>(s), 10, bidirectional_iterator<const char*>(s+10));
48 check_next_n(bidirectional_iterator<const char*>(s+10), -10, bidirectional_iterator<const char*>(s));
49 check_next_n(random_access_iterator<const char*>(s), 10, random_access_iterator<const char*>(s+10));
50 check_next_n(random_access_iterator<const char*>(s+10), -10, random_access_iterator<const char*>(s));
51 check_next_n(s, 10, s+10);
53 check_next_1(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1));
54 check_next_1(forward_iterator<const char*>(s), forward_iterator<const char*>(s+1));
55 check_next_1(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1));
56 check_next_1(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1));
57 check_next_1(s, s+1);
59 return true;
62 int main(int, char**)
64 tests();
65 #if TEST_STD_VER >= 17
66 static_assert(tests(), "");
67 #endif
68 return 0;