1 // Safe sequence implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file debug/safe_sequence.h
27 * This file is a GNU debug extension to the Standard C++ Library.
30 #ifndef _GLIBCXX_DEBUG_SAFE_SEQUENCE_H
31 #define _GLIBCXX_DEBUG_SAFE_SEQUENCE_H 1
33 #include <debug/debug.h>
34 #include <debug/macros.h>
35 #include <debug/functions.h>
36 #include <debug/safe_base.h>
40 template<typename _Iterator
, typename _Sequence
>
43 /** A simple function object that returns true if the passed-in
44 * value is not equal to the stored value. It saves typing over
45 * using both bind1st and not_equal.
47 template<typename _Type
>
53 explicit _Not_equal_to(const _Type
& __v
) : __value(__v
) { }
56 operator()(const _Type
& __x
) const
57 { return __value
!= __x
; }
60 /** A simple function object that returns true if the passed-in
61 * value is equal to the stored value. */
62 template <typename _Type
>
68 explicit _Equal_to(const _Type
& __v
) : __value(__v
) { }
71 operator()(const _Type
& __x
) const
72 { return __value
== __x
; }
75 /** A function object that returns true when the given random access
76 iterator is at least @c n steps away from the given iterator. */
77 template<typename _Iterator
>
80 typedef typename
std::iterator_traits
<_Iterator
>::difference_type
87 _After_nth_from(const difference_type
& __n
, const _Iterator
& __base
)
88 : _M_base(__base
), _M_n(__n
) { }
91 operator()(const _Iterator
& __x
) const
92 { return __x
- _M_base
>= _M_n
; }
96 * @brief Base class for constructing a @a safe sequence type that
97 * tracks iterators that reference it.
99 * The class template %_Safe_sequence simplifies the construction of
100 * @a safe sequences that track the iterators that reference the
101 * sequence, so that the iterators are notified of changes in the
102 * sequence that may affect their operation, e.g., if the container
103 * invalidates its iterators or is destructed. This class template
104 * may only be used by deriving from it and passing the name of the
105 * derived class as its template parameter via the curiously
106 * recurring template pattern. The derived class must have @c
107 * iterator and @c const_iterator types that are instantiations of
108 * class template _Safe_iterator for this sequence. Iterators will
109 * then be tracked automatically.
111 template<typename _Sequence
>
112 class _Safe_sequence
: public _Safe_sequence_base
115 /** Invalidates all iterators @c x that reference this sequence,
116 are not singular, and for which @c __pred(x) returns @c
117 true. @c __pred will be invoked with the normal iterators nested
119 template<typename _Predicate
>
121 _M_invalidate_if(_Predicate __pred
);
123 /** Transfers all iterators @c x that reference @c from sequence,
124 are not singular, and for which @c __pred(x) returns @c
125 true. @c __pred will be invoked with the normal iterators nested
127 template<typename _Predicate
>
129 _M_transfer_from_if(_Safe_sequence
& __from
, _Predicate __pred
);
131 } // namespace __gnu_debug
133 #include <debug/safe_sequence.tcc>