op_arrow.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// pointer 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 int get() const {return data_;} 30 31 friend bool operator==(const A& x, const A& y) 32 {return x.data_ == y.data_;} 33}; 34 35template <class It> 36class weird_iterator 37{ 38 It it_; 39public: 40 typedef It value_type; 41 typedef std::bidirectional_iterator_tag iterator_category; 42 typedef std::ptrdiff_t difference_type; 43 typedef It* pointer; 44 typedef It& reference; 45 46 weird_iterator() {} 47 explicit weird_iterator(It it) : it_(it) {} 48 ~weird_iterator() {it_ = It();} 49 50 reference operator*() {return it_;} 51 pointer operator->() {return &it_;} 52 53 weird_iterator& operator--() {return *this;} 54}; 55 56template <class It> 57void 58test(It i, typename std::iterator_traits<It>::value_type x) 59{ 60 std::reverse_iterator<It> r(i); 61 assert(r->get() == x.get()); 62} 63 64int main() 65{ 66 test(weird_iterator<A>(A()), A()); 67 A a; 68 test(&a+1, A()); 69} 70