1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <iterator>
11
12// reverse_iterator
13
14// requires RandomAccessIterator<Iter>
15//   constexpr reverse_iterator operator+(difference_type n) const;
16//
17// constexpr in c++17
18
19#include <iterator>
20#include <cassert>
21
22#include "test_macros.h"
23#include "test_iterators.h"
24
25template <class It>
26void
27test(It i, typename std::iterator_traits<It>::difference_type n, It x)
28{
29    const std::reverse_iterator<It> r(i);
30    std::reverse_iterator<It> rr = r + n;
31    assert(rr.base() == x);
32}
33
34int main()
35{
36    const char* s = "1234567890";
37    test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
38    test(s+5, 5, s);
39
40#if TEST_STD_VER > 14
41    {
42        constexpr const char *p = "123456789";
43        typedef std::reverse_iterator<const char *> RI;
44        constexpr RI it1 = std::make_reverse_iterator(p);
45        constexpr RI it2 = std::make_reverse_iterator(p + 5);
46        constexpr RI it3 = it2 + 5;
47        static_assert(it1 != it2, "");
48        static_assert(it1 == it3, "");
49        static_assert(it2 != it3, "");
50    }
51#endif
52}
53