1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
18 #include <type_traits>
20 #include "test_macros.h"
21 #include "test_iterators.h"
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
);
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));
65 #if TEST_STD_VER >= 17
66 static_assert(tests(), "");