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