1 // Profiling set implementation -*- C++ -*-
3 // Copyright (C) 2009, 2010 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 profile/set.h
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_SET_H
30 #define _GLIBCXX_PROFILE_SET_H 1
38 /// Class std::set wrapper with performance instrumentation.
39 template<typename _Key
, typename _Compare
= std::less
<_Key
>,
40 typename _Allocator
= std::allocator
<_Key
> >
42 : public _GLIBCXX_STD_D::set
<_Key
,_Compare
,_Allocator
>
44 typedef _GLIBCXX_STD_D::set
<_Key
, _Compare
, _Allocator
> _Base
;
48 typedef _Key key_type
;
49 typedef _Key value_type
;
50 typedef _Compare key_compare
;
51 typedef _Compare value_compare
;
52 typedef _Allocator allocator_type
;
53 typedef typename
_Base::reference reference
;
54 typedef typename
_Base::const_reference const_reference
;
56 typedef typename
_Base::iterator iterator
;
57 typedef typename
_Base::const_iterator const_iterator
;
58 typedef typename
_Base::reverse_iterator reverse_iterator
;
59 typedef typename
_Base::const_reverse_iterator const_reverse_iterator
;
61 typedef typename
_Base::size_type size_type
;
62 typedef typename
_Base::difference_type difference_type
;
63 typedef typename
_Base::pointer pointer
;
64 typedef typename
_Base::const_pointer const_pointer
;
66 // 23.3.3.1 construct/copy/destroy:
67 explicit set(const _Compare
& __comp
= _Compare(),
68 const _Allocator
& __a
= _Allocator())
69 : _Base(__comp
, __a
) { }
71 template<typename _InputIterator
>
72 set(_InputIterator __first
, _InputIterator __last
,
73 const _Compare
& __comp
= _Compare(),
74 const _Allocator
& __a
= _Allocator())
75 : _Base(__first
, __last
, __comp
, __a
) { }
83 #ifdef __GXX_EXPERIMENTAL_CXX0X__
85 : _Base(std::forward
<set
>(__x
))
88 set(initializer_list
<value_type
> __l
,
89 const _Compare
& __comp
= _Compare(),
90 const allocator_type
& __a
= allocator_type())
91 : _Base(__l
, __comp
, __a
) { }
97 operator=(const set
& __x
)
99 *static_cast<_Base
*>(this) = __x
;
103 #ifdef __GXX_EXPERIMENTAL_CXX0X__
115 operator=(initializer_list
<value_type
> __l
)
123 using _Base::get_allocator
;
128 { return iterator(_Base::begin()); }
132 { return const_iterator(_Base::begin()); }
136 { return iterator(_Base::end()); }
140 { return const_iterator(_Base::end()); }
144 { return reverse_iterator(end()); }
146 const_reverse_iterator
148 { return const_reverse_iterator(end()); }
152 { return reverse_iterator(begin()); }
154 const_reverse_iterator
156 { return const_reverse_iterator(begin()); }
158 #ifdef __GXX_EXPERIMENTAL_CXX0X__
161 { return const_iterator(_Base::begin()); }
165 { return const_iterator(_Base::end()); }
167 const_reverse_iterator
169 { return const_reverse_iterator(end()); }
171 const_reverse_iterator
173 { return const_reverse_iterator(begin()); }
179 using _Base::max_size
;
182 std::pair
<iterator
, bool>
183 insert(const value_type
& __x
)
185 typedef typename
_Base::iterator _Base_iterator
;
186 std::pair
<_Base_iterator
, bool> __res
= _Base::insert(__x
);
187 return std::pair
<iterator
, bool>(iterator(__res
.first
),
192 insert(iterator __position
, const value_type
& __x
)
194 return iterator(_Base::insert(__position
, __x
));
197 template <typename _InputIterator
>
199 insert(_InputIterator __first
, _InputIterator __last
)
201 _Base::insert(__first
, __last
);
204 #ifdef __GXX_EXPERIMENTAL_CXX0X__
206 insert(initializer_list
<value_type
> __l
)
207 { _Base::insert(__l
); }
210 #ifdef __GXX_EXPERIMENTAL_CXX0X__
212 erase(iterator __position
)
213 { return _Base::erase(__position
); }
216 erase(iterator __position
)
217 { _Base::erase(__position
); }
221 erase(const key_type
& __x
)
223 iterator __victim
= find(__x
);
224 if (__victim
== end())
228 _Base::erase(__victim
);
233 #ifdef __GXX_EXPERIMENTAL_CXX0X__
235 erase(iterator __first
, iterator __last
)
237 // _GLIBCXX_RESOLVE_LIB_DEFECTS
238 // 151. can't currently clear() empty container
239 while (__first
!= __last
)
240 this->erase(__first
++);
245 erase(iterator __first
, iterator __last
)
247 // _GLIBCXX_RESOLVE_LIB_DEFECTS
248 // 151. can't currently clear() empty container
249 while (__first
!= __last
)
250 this->erase(__first
++);
262 { this->erase(begin(), end()); }
265 using _Base::key_comp
;
266 using _Base::value_comp
;
270 find(const key_type
& __x
)
271 { return iterator(_Base::find(__x
)); }
273 // _GLIBCXX_RESOLVE_LIB_DEFECTS
274 // 214. set::find() missing const overload
276 find(const key_type
& __x
) const
277 { return const_iterator(_Base::find(__x
)); }
282 lower_bound(const key_type
& __x
)
283 { return iterator(_Base::lower_bound(__x
)); }
285 // _GLIBCXX_RESOLVE_LIB_DEFECTS
286 // 214. set::find() missing const overload
288 lower_bound(const key_type
& __x
) const
289 { return const_iterator(_Base::lower_bound(__x
)); }
292 upper_bound(const key_type
& __x
)
293 { return iterator(_Base::upper_bound(__x
)); }
295 // _GLIBCXX_RESOLVE_LIB_DEFECTS
296 // 214. set::find() missing const overload
298 upper_bound(const key_type
& __x
) const
299 { return const_iterator(_Base::upper_bound(__x
)); }
301 std::pair
<iterator
,iterator
>
302 equal_range(const key_type
& __x
)
304 typedef typename
_Base::iterator _Base_iterator
;
305 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
306 _Base::equal_range(__x
);
307 return std::make_pair(iterator(__res
.first
),
308 iterator(__res
.second
));
311 // _GLIBCXX_RESOLVE_LIB_DEFECTS
312 // 214. set::find() missing const overload
313 std::pair
<const_iterator
,const_iterator
>
314 equal_range(const key_type
& __x
) const
316 typedef typename
_Base::const_iterator _Base_iterator
;
317 std::pair
<_Base_iterator
, _Base_iterator
> __res
=
318 _Base::equal_range(__x
);
319 return std::make_pair(const_iterator(__res
.first
),
320 const_iterator(__res
.second
));
324 _M_base() { return *this; }
327 _M_base() const { return *this; }
331 template<typename _Key
, typename _Compare
, typename _Allocator
>
333 operator==(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
334 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
335 { return __lhs
._M_base() == __rhs
._M_base(); }
337 template<typename _Key
, typename _Compare
, typename _Allocator
>
339 operator!=(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
340 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
341 { return __lhs
._M_base() != __rhs
._M_base(); }
343 template<typename _Key
, typename _Compare
, typename _Allocator
>
345 operator<(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
346 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
347 { return __lhs
._M_base() < __rhs
._M_base(); }
349 template<typename _Key
, typename _Compare
, typename _Allocator
>
351 operator<=(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
352 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
353 { return __lhs
._M_base() <= __rhs
._M_base(); }
355 template<typename _Key
, typename _Compare
, typename _Allocator
>
357 operator>=(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
358 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
359 { return __lhs
._M_base() >= __rhs
._M_base(); }
361 template<typename _Key
, typename _Compare
, typename _Allocator
>
363 operator>(const set
<_Key
, _Compare
, _Allocator
>& __lhs
,
364 const set
<_Key
, _Compare
, _Allocator
>& __rhs
)
365 { return __lhs
._M_base() > __rhs
._M_base(); }
367 template<typename _Key
, typename _Compare
, typename _Allocator
>
369 swap(set
<_Key
, _Compare
, _Allocator
>& __x
,
370 set
<_Key
, _Compare
, _Allocator
>& __y
)
371 { return __x
.swap(__y
); }
373 } // namespace __profile