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 // All of these became constexpr in C++17
13 // template <InputIterator Iter, class Distance>
14 // constexpr void advance(Iter& i, Distance n);
16 // template <BidirectionalIterator Iter, class Distance>
17 // constexpr void advance(Iter& i, Distance n);
19 // template <RandomAccessIterator Iter, class Distance>
20 // constexpr void advance(Iter& i, Distance n);
22 // Make sure we catch forced conversions to the difference_type if they happen.
23 // ADDITIONAL_COMPILER_FLAGS: -Wsign-conversion
28 #include <type_traits>
30 #include "test_macros.h"
31 #include "test_iterators.h"
33 template <class Distance
, class It
>
35 void check_advance(It it
, Distance n
, It result
)
37 static_assert(std::is_same
<decltype(std::advance(it
, n
)), void>::value
, "");
42 TEST_CONSTEXPR_CXX17
bool tests()
44 const char* s
= "1234567890";
45 typedef std::iterator_traits
<const char*>::difference_type Distance
;
46 check_advance
<Distance
>(input_iterator
<const char*>(s
), 10, input_iterator
<const char*>(s
+10));
47 check_advance
<Distance
>(forward_iterator
<const char*>(s
), 10, forward_iterator
<const char*>(s
+10));
48 check_advance
<Distance
>(bidirectional_iterator
<const char*>(s
+5), 5, bidirectional_iterator
<const char*>(s
+10));
49 check_advance
<Distance
>(bidirectional_iterator
<const char*>(s
+5), -5, bidirectional_iterator
<const char*>(s
));
50 check_advance
<Distance
>(random_access_iterator
<const char*>(s
+5), 5, random_access_iterator
<const char*>(s
+10));
51 check_advance
<Distance
>(random_access_iterator
<const char*>(s
+5), -5, random_access_iterator
<const char*>(s
));
52 check_advance
<Distance
>(s
+5, 5, s
+10);
53 check_advance
<Distance
>(s
+5, -5, s
);
55 // Also check with other distance types
56 check_advance
<std::size_t>(input_iterator
<const char*>(s
), 10u, input_iterator
<const char*>(s
+10));
57 check_advance
<std::size_t>(forward_iterator
<const char*>(s
), 10u, forward_iterator
<const char*>(s
+10));
58 check_advance
<std::size_t>(bidirectional_iterator
<const char*>(s
), 10u, bidirectional_iterator
<const char*>(s
+10));
59 check_advance
<std::size_t>(random_access_iterator
<const char*>(s
), 10u, random_access_iterator
<const char*>(s
+10));
67 #if TEST_STD_VER >= 17
68 static_assert(tests(), "");