op_star.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
22class A
23{
24    int data_;
25public:
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
33template <class It>
34class weird_iterator
35{
36    It it_;
37public:
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
53template <class It>
54void
55test(It i, typename std::iterator_traits<It>::value_type x)
56{
57    std::reverse_iterator<It> r(i);
58    assert(*r == x);
59}
60
61int main()
62{
63    test(weird_iterator<A>(A()), A());
64    A a;
65    test(&a+1, A());
66}
67