1 // Copyright (C) 2017-2025 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 #include <testsuite_hooks.h>
27 static unsigned counter
= 0;
28 VERIFY(counter
< 100);
37 value(int i
= 0) : val(i
), id(next_id()) { values
[id
] = true; }
38 value(const value
& v
) : val(v
.val
), id(next_id()) { values
[id
] = true; }
39 value
& operator=(const value
& v
) { val
= v
.val
; return *this; }
40 ~value() { values
[id
] = false; }
43 bool operator<(const value
& lhs
, const value
& rhs
)
49 return lhs
.val
< rhs
.val
;
52 bool operator==(const value
& lhs
, const value
& rhs
)
58 return lhs
.val
== rhs
.val
;
61 // A forward iterator that fails to meet the requirement that for any
62 // two dereferenceable forward iterators, a == b implies &*a == &*b
63 struct stashing_iterator
65 typedef std::forward_iterator_tag iterator_category
;
66 typedef value value_type
;
67 typedef value_type
const* pointer
;
68 typedef value_type
const& reference
;
69 typedef std::ptrdiff_t difference_type
;
71 stashing_iterator() : ptr(), stashed() { }
72 stashing_iterator(pointer p
) : ptr(p
), stashed() { stash(); }
73 stashing_iterator(const stashing_iterator
&) = default;
74 stashing_iterator
& operator=(const stashing_iterator
&) = default;
76 stashing_iterator
& operator++()
83 stashing_iterator
operator++(int)
85 stashing_iterator i
= *this;
90 reference
operator*() const { return stashed
; }
91 pointer
operator->() const { return &**this; }
93 bool operator==(const stashing_iterator
& i
) const { return ptr
== i
.ptr
; }
94 bool operator!=(const stashing_iterator
& i
) const { return !(*this == i
); }
110 value s
[] = { 0, 1, 2, 3, 4, 5 };
111 std::search(s
, s
+6, stashing_iterator(s
), stashing_iterator(s
+4));
112 // { dg-warning "ignoring return value" "" { target c++11 } 111 }