Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / debug / safe_sequence.h
blob843c9b11710e2ae4589fd690a0b7e61ac465216a
1 // Safe sequence implementation -*- C++ -*-
3 // Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
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>
38 namespace __gnu_debug
40 template<typename _Iterator, typename _Sequence>
41 class _Safe_iterator;
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>
48 class _Not_equal_to
50 _Type __value;
52 public:
53 explicit _Not_equal_to(const _Type& __v) : __value(__v) { }
55 bool
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>
63 class _Equal_to
65 _Type __value;
67 public:
68 explicit _Equal_to(const _Type& __v) : __value(__v) { }
70 bool
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>
78 class _After_nth_from
80 typedef typename std::iterator_traits<_Iterator>::difference_type
81 difference_type;
83 _Iterator _M_base;
84 difference_type _M_n;
86 public:
87 _After_nth_from(const difference_type& __n, const _Iterator& __base)
88 : _M_base(__base), _M_n(__n) { }
90 bool
91 operator()(const _Iterator& __x) const
92 { return __x - _M_base >= _M_n; }
95 /**
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 @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
114 public:
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
118 in the safe ones. */
119 template<typename _Predicate>
120 void
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
126 in the safe ones. */
127 template<typename _Predicate>
128 void
129 _M_transfer_from_if(_Safe_sequence& __from, _Predicate __pred);
131 } // namespace __gnu_debug
133 #ifndef _GLIBCXX_EXPORT_TEMPLATE
134 # include <debug/safe_sequence.tcc>
135 #endif
137 #endif