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 //===----------------------------------------------------------------------===// 8 9 // <iterator> 10 11 // reverse_iterator 12 13 // requires RandomAccessIterator<Iter> 14 // reverse_iterator& operator+=(difference_type n); // constexpr in C++17 15 16 #include <iterator> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "test_iterators.h" 21 22 template <class It> 23 TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) { 24 std::reverse_iterator<It> r(i); 25 std::reverse_iterator<It>& rr = r += n; 26 assert(r.base() == x); 27 assert(&rr == &r); 28 } 29 30 TEST_CONSTEXPR_CXX17 bool tests() { 31 char const* s = "1234567890"; 32 test(random_access_iterator<const char*>(s + 5), 5, random_access_iterator<const char*>(s)); 33 #if TEST_STD_VER >= 20 34 test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s)); 35 #endif 36 test(s+5, 5, s); 37 return true; 38 } 39 40 int main(int, char**) { 41 tests(); 42 #if TEST_STD_VER > 14 43 static_assert(tests(), ""); 44 #endif 45 return 0; 46 } 47