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 // reference operator*() const; // constexpr in C++17
14 
15 // Be sure to respect LWG 198:
16 //    http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
17 // LWG 198 was superseded by LWG 2360
18 //    http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
19 
20 #include <iterator>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
25 class A
26 {
27     int data_;
28 public:
A()29     A() : data_(1) {}
~A()30     ~A() {data_ = -1;}
31 
operator ==(const A & x,const A & y)32     friend bool operator==(const A& x, const A& y)
33         {return x.data_ == y.data_;}
34 };
35 
36 template <class It>
37 void
test(It i,typename std::iterator_traits<It>::value_type x)38 test(It i, typename std::iterator_traits<It>::value_type x)
39 {
40     std::reverse_iterator<It> r(i);
41     assert(*r == x);
42 }
43 
main(int,char **)44 int main(int, char**)
45 {
46     A a;
47     test(&a+1, A());
48 
49 #if TEST_STD_VER > 14
50     {
51         constexpr const char *p = "123456789";
52         typedef std::reverse_iterator<const char *> RI;
53         constexpr RI it1 = std::make_reverse_iterator(p+1);
54         constexpr RI it2 = std::make_reverse_iterator(p+2);
55         static_assert(*it1 == p[0], "");
56         static_assert(*it2 == p[1], "");
57     }
58 #endif
59 
60   return 0;
61 }
62