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

source code of libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp