1 // Copyright (C) 2018 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++11 } }
21 // LWG 1052. reverse_iterator::operator-> should also support smart pointers
22 // LWG 2775. reverse_iterator is does not compile for fancy pointers
25 #include <testsuite_hooks.h>
30 // Example 1 from LWG 1052
37 typedef std::bidirectional_iterator_tag iterator_category
;
41 pointer(X
& v
) : value(v
) {}
43 X
* operator->() const {return &value
;}
45 typedef std::ptrdiff_t difference_type
;
47 // additional iterator requirements not important for this issue
49 reference
operator*() const { return x
; }
50 pointer
operator->() const { return pointer(x
); }
51 IterX
& operator--() {return *this;}
55 std::reverse_iterator
<IterX
> ix
;
56 VERIFY( &ix
->m
== &(*ix
).m
);
62 // Example 2 from LWG 1052
65 P() : first(10), second(20.0) { }
70 std::reverse_iterator
<P
*> ri(&op
+ 1);
71 VERIFY( ri
->first
== 10 );
74 // N.B. Example 3 from LWG 1052 isn't expected to work,
75 // because a caching iterator like IterX is not a forward iterator.