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 // reference operator*() const;
15 
16 // Be sure to respect LWG 198:
17 //    http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
18 
19 #include <iterator>
20 #include <cassert>
21 
22 class A
23 {
24     int data_;
25 public:
26     A() : data_(1) {}
27     ~A() {data_ = -1;}
28 
29     friend bool operator==(const A& x, const A& y)
30         {return x.data_ == y.data_;}
31 };
32 
33 template <class It>
34 class weird_iterator
35 {
36     It it_;
37 public:
38     typedef It                              value_type;
39     typedef std::bidirectional_iterator_tag iterator_category;
40     typedef std::ptrdiff_t                  difference_type;
41     typedef It*                             pointer;
42     typedef It&                             reference;
43 
44     weird_iterator() {}
45     explicit weird_iterator(It it) : it_(it) {}
46     ~weird_iterator() {it_ = It();}
47 
48     reference operator*() {return it_;}
49 
50     weird_iterator& operator--() {return *this;}
51 };
52 
53 template <class It>
54 void
55 test(It i, typename std::iterator_traits<It>::value_type x)
56 {
57     std::reverse_iterator<It> r(i);
58     assert(*r == x);
59 }
60 
61 int main()
62 {
63     test(weird_iterator<A>(A()), A());
64     A a;
65     test(&a+1, A());
66 }
67