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// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
15//   requires HasMinus<Iter2, Iter1>
16//   auto operator-(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y)
17//   -> decltype(y.base() - x.base());
18
19#include <iterator>
20#include <cstddef>
21#include <cassert>
22
23#include "test_iterators.h"
24
25template <class It1, class It2>
26void
27test(It1 l, It2 r, std::ptrdiff_t x)
28{
29    const std::reverse_iterator<It1> r1(l);
30    const std::reverse_iterator<It2> r2(r);
31    assert((r1 - r2) == x);
32}
33
34int main()
35{
36    char s[3] = {0};
37    test(random_access_iterator<const char*>(s), random_access_iterator<char*>(s), 0);
38    test(random_access_iterator<char*>(s), random_access_iterator<const char*>(s+1), 1);
39    test(random_access_iterator<const char*>(s+1), random_access_iterator<char*>(s), -1);
40    test(s, s, 0);
41    test(s, s+1, 1);
42    test(s+1, s, -1);
43}
44