1*38fd1498Szrj // Profiling set implementation -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj // Copyright (C) 2009-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj /** @file profile/set.h
26*38fd1498Szrj * This file is a GNU profile extension to the Standard C++ Library.
27*38fd1498Szrj */
28*38fd1498Szrj
29*38fd1498Szrj #ifndef _GLIBCXX_PROFILE_SET_H
30*38fd1498Szrj #define _GLIBCXX_PROFILE_SET_H 1
31*38fd1498Szrj
32*38fd1498Szrj #include <profile/base.h>
33*38fd1498Szrj #include <profile/ordered_base.h>
34*38fd1498Szrj
_GLIBCXX_VISIBILITY(default)35*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
36*38fd1498Szrj {
37*38fd1498Szrj namespace __profile
38*38fd1498Szrj {
39*38fd1498Szrj /// Class std::set wrapper with performance instrumentation.
40*38fd1498Szrj template<typename _Key, typename _Compare = std::less<_Key>,
41*38fd1498Szrj typename _Allocator = std::allocator<_Key> >
42*38fd1498Szrj class set
43*38fd1498Szrj : public _GLIBCXX_STD_C::set<_Key,_Compare,_Allocator>,
44*38fd1498Szrj public _Ordered_profile<set<_Key, _Compare, _Allocator> >
45*38fd1498Szrj {
46*38fd1498Szrj typedef _GLIBCXX_STD_C::set<_Key, _Compare, _Allocator> _Base;
47*38fd1498Szrj
48*38fd1498Szrj typedef typename _Base::iterator _Base_iterator;
49*38fd1498Szrj typedef typename _Base::const_iterator _Base_const_iterator;
50*38fd1498Szrj
51*38fd1498Szrj public:
52*38fd1498Szrj // types:
53*38fd1498Szrj typedef _Key key_type;
54*38fd1498Szrj typedef _Key value_type;
55*38fd1498Szrj typedef _Compare key_compare;
56*38fd1498Szrj typedef _Compare value_compare;
57*38fd1498Szrj typedef typename _Base::reference reference;
58*38fd1498Szrj typedef typename _Base::const_reference const_reference;
59*38fd1498Szrj
60*38fd1498Szrj typedef __iterator_tracker<_Base_iterator, set> iterator;
61*38fd1498Szrj typedef __iterator_tracker<_Base_const_iterator,
62*38fd1498Szrj set> const_iterator;
63*38fd1498Szrj typedef std::reverse_iterator<iterator> reverse_iterator;
64*38fd1498Szrj typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
65*38fd1498Szrj
66*38fd1498Szrj typedef typename _Base::size_type size_type;
67*38fd1498Szrj typedef typename _Base::difference_type difference_type;
68*38fd1498Szrj
69*38fd1498Szrj // 23.3.3.1 construct/copy/destroy:
70*38fd1498Szrj #if __cplusplus < 201103L
71*38fd1498Szrj set()
72*38fd1498Szrj : _Base() { }
73*38fd1498Szrj set(const set& __x)
74*38fd1498Szrj : _Base(__x) { }
75*38fd1498Szrj ~set() { }
76*38fd1498Szrj #else
77*38fd1498Szrj set() = default;
78*38fd1498Szrj set(const set&) = default;
79*38fd1498Szrj set(set&&) = default;
80*38fd1498Szrj ~set() = default;
81*38fd1498Szrj #endif
82*38fd1498Szrj
83*38fd1498Szrj explicit set(const _Compare& __comp,
84*38fd1498Szrj const _Allocator& __a = _Allocator())
85*38fd1498Szrj : _Base(__comp, __a) { }
86*38fd1498Szrj
87*38fd1498Szrj #if __cplusplus >= 201103L
88*38fd1498Szrj template<typename _InputIterator,
89*38fd1498Szrj typename = std::_RequireInputIter<_InputIterator>>
90*38fd1498Szrj #else
91*38fd1498Szrj template<typename _InputIterator>
92*38fd1498Szrj #endif
93*38fd1498Szrj set(_InputIterator __first, _InputIterator __last,
94*38fd1498Szrj const _Compare& __comp = _Compare(),
95*38fd1498Szrj const _Allocator& __a = _Allocator())
96*38fd1498Szrj : _Base(__first, __last, __comp, __a) { }
97*38fd1498Szrj
98*38fd1498Szrj #if __cplusplus >= 201103L
99*38fd1498Szrj set(initializer_list<value_type> __l,
100*38fd1498Szrj const _Compare& __comp = _Compare(),
101*38fd1498Szrj const _Allocator& __a = _Allocator())
102*38fd1498Szrj : _Base(__l, __comp, __a) { }
103*38fd1498Szrj
104*38fd1498Szrj explicit
105*38fd1498Szrj set(const _Allocator& __a)
106*38fd1498Szrj : _Base(__a) { }
107*38fd1498Szrj
108*38fd1498Szrj set(const set& __x, const _Allocator& __a)
109*38fd1498Szrj : _Base(__x, __a) { }
110*38fd1498Szrj
111*38fd1498Szrj set(set&& __x, const _Allocator& __a)
112*38fd1498Szrj noexcept( noexcept(_Base(std::move(__x), __a)) )
113*38fd1498Szrj : _Base(std::move(__x), __a) { }
114*38fd1498Szrj
115*38fd1498Szrj set(initializer_list<value_type> __l, const _Allocator& __a)
116*38fd1498Szrj : _Base(__l, __a) { }
117*38fd1498Szrj
118*38fd1498Szrj template<typename _InputIterator>
119*38fd1498Szrj set(_InputIterator __first, _InputIterator __last,
120*38fd1498Szrj const _Allocator& __a)
121*38fd1498Szrj : _Base(__first, __last, __a) { }
122*38fd1498Szrj #endif
123*38fd1498Szrj
124*38fd1498Szrj set(const _Base& __x)
125*38fd1498Szrj : _Base(__x) { }
126*38fd1498Szrj
127*38fd1498Szrj #if __cplusplus < 201103L
128*38fd1498Szrj set&
129*38fd1498Szrj operator=(const set& __x)
130*38fd1498Szrj {
131*38fd1498Szrj this->_M_profile_destruct();
132*38fd1498Szrj _M_base() = __x;
133*38fd1498Szrj this->_M_profile_construct();
134*38fd1498Szrj return *this;
135*38fd1498Szrj }
136*38fd1498Szrj #else
137*38fd1498Szrj set&
138*38fd1498Szrj operator=(const set&) = default;
139*38fd1498Szrj
140*38fd1498Szrj set&
141*38fd1498Szrj operator=(set&&) = default;
142*38fd1498Szrj
143*38fd1498Szrj set&
144*38fd1498Szrj operator=(initializer_list<value_type> __l)
145*38fd1498Szrj {
146*38fd1498Szrj this->_M_profile_destruct();
147*38fd1498Szrj _M_base() = __l;
148*38fd1498Szrj this->_M_profile_construct();
149*38fd1498Szrj return *this;
150*38fd1498Szrj }
151*38fd1498Szrj #endif
152*38fd1498Szrj
153*38fd1498Szrj // iterators
154*38fd1498Szrj iterator
155*38fd1498Szrj begin() _GLIBCXX_NOEXCEPT
156*38fd1498Szrj { return iterator(_Base::begin(), this); }
157*38fd1498Szrj
158*38fd1498Szrj const_iterator
159*38fd1498Szrj begin() const _GLIBCXX_NOEXCEPT
160*38fd1498Szrj { return const_iterator(_Base::begin(), this); }
161*38fd1498Szrj
162*38fd1498Szrj iterator
163*38fd1498Szrj end() _GLIBCXX_NOEXCEPT
164*38fd1498Szrj { return iterator(_Base::end(), this); }
165*38fd1498Szrj
166*38fd1498Szrj const_iterator
167*38fd1498Szrj end() const _GLIBCXX_NOEXCEPT
168*38fd1498Szrj { return const_iterator(_Base::end(), this); }
169*38fd1498Szrj
170*38fd1498Szrj #if __cplusplus >= 201103L
171*38fd1498Szrj const_iterator
172*38fd1498Szrj cbegin() const noexcept
173*38fd1498Szrj { return const_iterator(_Base::cbegin(), this); }
174*38fd1498Szrj
175*38fd1498Szrj const_iterator
176*38fd1498Szrj cend() const noexcept
177*38fd1498Szrj { return const_iterator(_Base::cend(), this); }
178*38fd1498Szrj #endif
179*38fd1498Szrj
180*38fd1498Szrj reverse_iterator
181*38fd1498Szrj rbegin() _GLIBCXX_NOEXCEPT
182*38fd1498Szrj {
183*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
184*38fd1498Szrj return reverse_iterator(end());
185*38fd1498Szrj }
186*38fd1498Szrj
187*38fd1498Szrj const_reverse_iterator
188*38fd1498Szrj rbegin() const _GLIBCXX_NOEXCEPT
189*38fd1498Szrj {
190*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
191*38fd1498Szrj return const_reverse_iterator(end());
192*38fd1498Szrj }
193*38fd1498Szrj
194*38fd1498Szrj reverse_iterator
195*38fd1498Szrj rend() _GLIBCXX_NOEXCEPT
196*38fd1498Szrj {
197*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
198*38fd1498Szrj return reverse_iterator(begin());
199*38fd1498Szrj }
200*38fd1498Szrj
201*38fd1498Szrj const_reverse_iterator
202*38fd1498Szrj rend() const _GLIBCXX_NOEXCEPT
203*38fd1498Szrj {
204*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
205*38fd1498Szrj return const_reverse_iterator(begin());
206*38fd1498Szrj }
207*38fd1498Szrj
208*38fd1498Szrj #if __cplusplus >= 201103L
209*38fd1498Szrj const_reverse_iterator
210*38fd1498Szrj crbegin() const noexcept
211*38fd1498Szrj {
212*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
213*38fd1498Szrj return const_reverse_iterator(cend());
214*38fd1498Szrj }
215*38fd1498Szrj
216*38fd1498Szrj const_reverse_iterator
217*38fd1498Szrj crend() const noexcept
218*38fd1498Szrj {
219*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
220*38fd1498Szrj return const_reverse_iterator(cbegin());
221*38fd1498Szrj }
222*38fd1498Szrj #endif
223*38fd1498Szrj
224*38fd1498Szrj void
225*38fd1498Szrj swap(set& __x)
226*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
227*38fd1498Szrj {
228*38fd1498Szrj _Base::swap(__x);
229*38fd1498Szrj this->_M_swap(__x);
230*38fd1498Szrj }
231*38fd1498Szrj
232*38fd1498Szrj // modifiers:
233*38fd1498Szrj #if __cplusplus >= 201103L
234*38fd1498Szrj template<typename... _Args>
235*38fd1498Szrj std::pair<iterator, bool>
236*38fd1498Szrj emplace(_Args&&... __args)
237*38fd1498Szrj {
238*38fd1498Szrj __profcxx_map2umap_insert(this->_M_map2umap_info, this->size(), 1);
239*38fd1498Szrj auto __base_ret = _Base::emplace(std::forward<_Args>(__args)...);
240*38fd1498Szrj return std::make_pair(iterator(__base_ret.first, this),
241*38fd1498Szrj __base_ret.second);
242*38fd1498Szrj }
243*38fd1498Szrj
244*38fd1498Szrj template<typename... _Args>
245*38fd1498Szrj iterator
246*38fd1498Szrj emplace_hint(const_iterator __pos, _Args&&... __args)
247*38fd1498Szrj {
248*38fd1498Szrj auto size_before = this->size();
249*38fd1498Szrj auto __res
250*38fd1498Szrj = _Base::emplace_hint(__pos.base(), std::forward<_Args>(__args)...);
251*38fd1498Szrj __profcxx_map2umap_insert(this->_M_map2umap_info,
252*38fd1498Szrj size_before, _M_hint_used(__pos.base(), __res) ? 0 : 1);
253*38fd1498Szrj return iterator(__res, this);
254*38fd1498Szrj }
255*38fd1498Szrj #endif
256*38fd1498Szrj
257*38fd1498Szrj std::pair<iterator, bool>
258*38fd1498Szrj insert(const value_type& __x)
259*38fd1498Szrj {
260*38fd1498Szrj __profcxx_map2umap_insert(this->_M_map2umap_info, this->size(), 1);
261*38fd1498Szrj std::pair<_Base_iterator, bool> __base_ret = _Base::insert(__x);
262*38fd1498Szrj return std::make_pair(iterator(__base_ret.first, this),
263*38fd1498Szrj __base_ret.second);
264*38fd1498Szrj }
265*38fd1498Szrj
266*38fd1498Szrj #if __cplusplus >= 201103L
267*38fd1498Szrj std::pair<iterator, bool>
268*38fd1498Szrj insert(value_type&& __x)
269*38fd1498Szrj {
270*38fd1498Szrj __profcxx_map2umap_insert(this->_M_map2umap_info, this->size(), 1);
271*38fd1498Szrj std::pair<_Base_iterator, bool> __base_ret
272*38fd1498Szrj = _Base::insert(std::move(__x));
273*38fd1498Szrj return std::make_pair(iterator(__base_ret.first, this),
274*38fd1498Szrj __base_ret.second);
275*38fd1498Szrj }
276*38fd1498Szrj #endif
277*38fd1498Szrj
278*38fd1498Szrj iterator
279*38fd1498Szrj insert(const_iterator __pos, const value_type& __x)
280*38fd1498Szrj {
281*38fd1498Szrj size_type size_before = this->size();
282*38fd1498Szrj _Base_iterator __res = _Base::insert(__pos.base(), __x);
283*38fd1498Szrj __profcxx_map2umap_insert(this->_M_map2umap_info,
284*38fd1498Szrj size_before, _M_hint_used(__pos.base(), __res) ? 0 : 1);
285*38fd1498Szrj return iterator(__res, this);
286*38fd1498Szrj }
287*38fd1498Szrj
288*38fd1498Szrj #if __cplusplus >= 201103L
289*38fd1498Szrj iterator
290*38fd1498Szrj insert(const_iterator __pos, value_type&& __x)
291*38fd1498Szrj { return iterator(_Base::insert(__pos.base(), std::move(__x)), this); }
292*38fd1498Szrj #endif
293*38fd1498Szrj
294*38fd1498Szrj template<typename _InputIterator>
295*38fd1498Szrj void
296*38fd1498Szrj insert(_InputIterator __first, _InputIterator __last)
297*38fd1498Szrj {
298*38fd1498Szrj for (; __first != __last; ++__first)
299*38fd1498Szrj insert(*__first);
300*38fd1498Szrj }
301*38fd1498Szrj
302*38fd1498Szrj #if __cplusplus >= 201103L
303*38fd1498Szrj void
304*38fd1498Szrj insert(initializer_list<value_type> __l)
305*38fd1498Szrj { insert(__l.begin(), __l.end()); }
306*38fd1498Szrj #endif
307*38fd1498Szrj
308*38fd1498Szrj #if __cplusplus >= 201103L
309*38fd1498Szrj iterator
310*38fd1498Szrj erase(const_iterator __pos)
311*38fd1498Szrj {
312*38fd1498Szrj __profcxx_map2umap_erase(this->_M_map2umap_info, this->size(), 1);
313*38fd1498Szrj return iterator(_Base::erase(__pos.base()), this);
314*38fd1498Szrj }
315*38fd1498Szrj #else
316*38fd1498Szrj void
317*38fd1498Szrj erase(iterator __pos)
318*38fd1498Szrj {
319*38fd1498Szrj __profcxx_map2umap_erase(this->_M_map2umap_info, this->size(), 1);
320*38fd1498Szrj _Base::erase(__pos.base());
321*38fd1498Szrj }
322*38fd1498Szrj #endif
323*38fd1498Szrj
324*38fd1498Szrj size_type
325*38fd1498Szrj erase(const key_type& __x)
326*38fd1498Szrj {
327*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
328*38fd1498Szrj __profcxx_map2umap_erase(this->_M_map2umap_info, this->size(), 1);
329*38fd1498Szrj return _Base::erase(__x);
330*38fd1498Szrj }
331*38fd1498Szrj
332*38fd1498Szrj #if __cplusplus >= 201103L
333*38fd1498Szrj iterator
334*38fd1498Szrj erase(const_iterator __first, const_iterator __last)
335*38fd1498Szrj {
336*38fd1498Szrj if (__first != __last)
337*38fd1498Szrj {
338*38fd1498Szrj iterator __ret;
339*38fd1498Szrj for (; __first != __last;)
340*38fd1498Szrj __ret = erase(__first++);
341*38fd1498Szrj return __ret;
342*38fd1498Szrj }
343*38fd1498Szrj
344*38fd1498Szrj return iterator(_Base::erase(__first.base(), __last.base()), this);
345*38fd1498Szrj }
346*38fd1498Szrj #else
347*38fd1498Szrj void
348*38fd1498Szrj erase(iterator __first, iterator __last)
349*38fd1498Szrj {
350*38fd1498Szrj for (; __first != __last;)
351*38fd1498Szrj erase(__first++);
352*38fd1498Szrj }
353*38fd1498Szrj #endif
354*38fd1498Szrj
355*38fd1498Szrj void
356*38fd1498Szrj clear() _GLIBCXX_NOEXCEPT
357*38fd1498Szrj {
358*38fd1498Szrj this->_M_profile_destruct();
359*38fd1498Szrj _Base::clear();
360*38fd1498Szrj this->_M_profile_construct();
361*38fd1498Szrj }
362*38fd1498Szrj
363*38fd1498Szrj size_type
364*38fd1498Szrj count(const key_type& __x) const
365*38fd1498Szrj {
366*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
367*38fd1498Szrj return _Base::count(__x);
368*38fd1498Szrj }
369*38fd1498Szrj
370*38fd1498Szrj #if __cplusplus > 201103L
371*38fd1498Szrj template<typename _Kt,
372*38fd1498Szrj typename _Req =
373*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
374*38fd1498Szrj size_type
375*38fd1498Szrj count(const _Kt& __x) const
376*38fd1498Szrj {
377*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
378*38fd1498Szrj return _Base::count(__x);
379*38fd1498Szrj }
380*38fd1498Szrj #endif
381*38fd1498Szrj
382*38fd1498Szrj // set operations:
383*38fd1498Szrj iterator
384*38fd1498Szrj find(const key_type& __x)
385*38fd1498Szrj {
386*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
387*38fd1498Szrj return iterator(_Base::find(__x), this);
388*38fd1498Szrj }
389*38fd1498Szrj
390*38fd1498Szrj const_iterator
391*38fd1498Szrj find(const key_type& __x) const
392*38fd1498Szrj {
393*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
394*38fd1498Szrj return const_iterator(_Base::find(__x), this);
395*38fd1498Szrj }
396*38fd1498Szrj
397*38fd1498Szrj #if __cplusplus > 201103L
398*38fd1498Szrj template<typename _Kt,
399*38fd1498Szrj typename _Req =
400*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
401*38fd1498Szrj iterator
402*38fd1498Szrj find(const _Kt& __x)
403*38fd1498Szrj {
404*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
405*38fd1498Szrj return { _Base::find(__x), this };
406*38fd1498Szrj }
407*38fd1498Szrj
408*38fd1498Szrj template<typename _Kt,
409*38fd1498Szrj typename _Req =
410*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
411*38fd1498Szrj const_iterator
412*38fd1498Szrj find(const _Kt& __x) const
413*38fd1498Szrj {
414*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
415*38fd1498Szrj return { _Base::find(__x), this };
416*38fd1498Szrj }
417*38fd1498Szrj #endif
418*38fd1498Szrj
419*38fd1498Szrj iterator
420*38fd1498Szrj lower_bound(const key_type& __x)
421*38fd1498Szrj {
422*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
423*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
424*38fd1498Szrj return iterator(_Base::lower_bound(__x), this);
425*38fd1498Szrj }
426*38fd1498Szrj
427*38fd1498Szrj const_iterator
428*38fd1498Szrj lower_bound(const key_type& __x) const
429*38fd1498Szrj {
430*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
431*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
432*38fd1498Szrj return const_iterator(_Base::lower_bound(__x), this);
433*38fd1498Szrj }
434*38fd1498Szrj
435*38fd1498Szrj #if __cplusplus > 201103L
436*38fd1498Szrj template<typename _Kt,
437*38fd1498Szrj typename _Req =
438*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
439*38fd1498Szrj iterator
440*38fd1498Szrj lower_bound(const _Kt& __x)
441*38fd1498Szrj {
442*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
443*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
444*38fd1498Szrj return { _Base::lower_bound(__x), this };
445*38fd1498Szrj }
446*38fd1498Szrj
447*38fd1498Szrj template<typename _Kt,
448*38fd1498Szrj typename _Req =
449*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
450*38fd1498Szrj const_iterator
451*38fd1498Szrj lower_bound(const _Kt& __x) const
452*38fd1498Szrj {
453*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
454*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
455*38fd1498Szrj return { _Base::lower_bound(__x), this };
456*38fd1498Szrj }
457*38fd1498Szrj #endif
458*38fd1498Szrj
459*38fd1498Szrj iterator
460*38fd1498Szrj upper_bound(const key_type& __x)
461*38fd1498Szrj {
462*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
463*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
464*38fd1498Szrj return iterator(_Base::upper_bound(__x), this);
465*38fd1498Szrj }
466*38fd1498Szrj
467*38fd1498Szrj const_iterator
468*38fd1498Szrj upper_bound(const key_type& __x) const
469*38fd1498Szrj {
470*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
471*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
472*38fd1498Szrj return const_iterator(_Base::upper_bound(__x), this);
473*38fd1498Szrj }
474*38fd1498Szrj
475*38fd1498Szrj #if __cplusplus > 201103L
476*38fd1498Szrj template<typename _Kt,
477*38fd1498Szrj typename _Req =
478*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
479*38fd1498Szrj iterator
480*38fd1498Szrj upper_bound(const _Kt& __x)
481*38fd1498Szrj {
482*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
483*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
484*38fd1498Szrj return { _Base::upper_bound(__x), this };
485*38fd1498Szrj }
486*38fd1498Szrj
487*38fd1498Szrj template<typename _Kt,
488*38fd1498Szrj typename _Req =
489*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
490*38fd1498Szrj const_iterator
491*38fd1498Szrj upper_bound(const _Kt& __x) const
492*38fd1498Szrj {
493*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
494*38fd1498Szrj __profcxx_map2umap_invalidate(this->_M_map2umap_info);
495*38fd1498Szrj return { _Base::upper_bound(__x), this };
496*38fd1498Szrj }
497*38fd1498Szrj #endif
498*38fd1498Szrj
499*38fd1498Szrj std::pair<iterator, iterator>
500*38fd1498Szrj equal_range(const key_type& __x)
501*38fd1498Szrj {
502*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
503*38fd1498Szrj std::pair<_Base_iterator, _Base_iterator> __base_ret
504*38fd1498Szrj = _Base::equal_range(__x);
505*38fd1498Szrj return std::make_pair(iterator(__base_ret.first, this),
506*38fd1498Szrj iterator(__base_ret.second, this));
507*38fd1498Szrj }
508*38fd1498Szrj
509*38fd1498Szrj std::pair<const_iterator, const_iterator>
510*38fd1498Szrj equal_range(const key_type& __x) const
511*38fd1498Szrj {
512*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
513*38fd1498Szrj std::pair<_Base_const_iterator, _Base_const_iterator> __base_ret
514*38fd1498Szrj = _Base::equal_range(__x);
515*38fd1498Szrj return std::make_pair(const_iterator(__base_ret.first, this),
516*38fd1498Szrj const_iterator(__base_ret.second, this));
517*38fd1498Szrj }
518*38fd1498Szrj
519*38fd1498Szrj #if __cplusplus > 201103L
520*38fd1498Szrj template<typename _Kt,
521*38fd1498Szrj typename _Req =
522*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
523*38fd1498Szrj std::pair<iterator, iterator>
524*38fd1498Szrj equal_range(const _Kt& __x)
525*38fd1498Szrj {
526*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
527*38fd1498Szrj auto __res = _Base::equal_range(__x);
528*38fd1498Szrj return { { __res.first, this }, { __res.second, this } };
529*38fd1498Szrj }
530*38fd1498Szrj
531*38fd1498Szrj template<typename _Kt,
532*38fd1498Szrj typename _Req =
533*38fd1498Szrj typename __has_is_transparent<_Compare, _Kt>::type>
534*38fd1498Szrj std::pair<const_iterator, const_iterator>
535*38fd1498Szrj equal_range(const _Kt& __x) const
536*38fd1498Szrj {
537*38fd1498Szrj __profcxx_map2umap_find(this->_M_map2umap_info, this->size());
538*38fd1498Szrj auto __res = _Base::equal_range(__x);
539*38fd1498Szrj return { { __res.first, this }, { __res.second, this } };
540*38fd1498Szrj }
541*38fd1498Szrj #endif
542*38fd1498Szrj
543*38fd1498Szrj _Base&
544*38fd1498Szrj _M_base() _GLIBCXX_NOEXCEPT { return *this; }
545*38fd1498Szrj
546*38fd1498Szrj const _Base&
547*38fd1498Szrj _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
548*38fd1498Szrj
549*38fd1498Szrj private:
550*38fd1498Szrj /** If hint is used we consider that the map and unordered_map
551*38fd1498Szrj * operations have equivalent insertion cost so we do not update metrics
552*38fd1498Szrj * about it.
553*38fd1498Szrj * Note that to find out if hint has been used is libstdc++
554*38fd1498Szrj * implementation dependent.
555*38fd1498Szrj */
556*38fd1498Szrj bool
557*38fd1498Szrj _M_hint_used(_Base_const_iterator __hint, _Base_iterator __res)
558*38fd1498Szrj {
559*38fd1498Szrj return (__hint == __res
560*38fd1498Szrj || (__hint == _M_base().end() && ++__res == _M_base().end())
561*38fd1498Szrj || (__hint != _M_base().end() && (++__hint == __res
562*38fd1498Szrj || ++__res == --__hint)));
563*38fd1498Szrj }
564*38fd1498Szrj
565*38fd1498Szrj template<typename _K1, typename _C1, typename _A1>
566*38fd1498Szrj friend bool
567*38fd1498Szrj operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
568*38fd1498Szrj
569*38fd1498Szrj template<typename _K1, typename _C1, typename _A1>
570*38fd1498Szrj friend bool
571*38fd1498Szrj operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&);
572*38fd1498Szrj };
573*38fd1498Szrj
574*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
575*38fd1498Szrj inline bool
576*38fd1498Szrj operator==(const set<_Key, _Compare, _Allocator>& __lhs,
577*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
578*38fd1498Szrj {
579*38fd1498Szrj __profcxx_map2umap_invalidate(__lhs._M_map2umap_info);
580*38fd1498Szrj __profcxx_map2umap_invalidate(__rhs._M_map2umap_info);
581*38fd1498Szrj return __lhs._M_base() == __rhs._M_base();
582*38fd1498Szrj }
583*38fd1498Szrj
584*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
585*38fd1498Szrj inline bool
586*38fd1498Szrj operator<(const set<_Key, _Compare, _Allocator>& __lhs,
587*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
588*38fd1498Szrj {
589*38fd1498Szrj __profcxx_map2umap_invalidate(__lhs._M_map2umap_info);
590*38fd1498Szrj __profcxx_map2umap_invalidate(__rhs._M_map2umap_info);
591*38fd1498Szrj return __lhs._M_base() < __rhs._M_base();
592*38fd1498Szrj }
593*38fd1498Szrj
594*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
595*38fd1498Szrj inline bool
596*38fd1498Szrj operator!=(const set<_Key, _Compare, _Allocator>& __lhs,
597*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
598*38fd1498Szrj { return !(__lhs == __rhs); }
599*38fd1498Szrj
600*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
601*38fd1498Szrj inline bool
602*38fd1498Szrj operator<=(const set<_Key, _Compare, _Allocator>& __lhs,
603*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
604*38fd1498Szrj { return !(__rhs < __lhs); }
605*38fd1498Szrj
606*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
607*38fd1498Szrj inline bool
608*38fd1498Szrj operator>=(const set<_Key, _Compare, _Allocator>& __lhs,
609*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
610*38fd1498Szrj { return !(__lhs < __rhs); }
611*38fd1498Szrj
612*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
613*38fd1498Szrj inline bool
614*38fd1498Szrj operator>(const set<_Key, _Compare, _Allocator>& __lhs,
615*38fd1498Szrj const set<_Key, _Compare, _Allocator>& __rhs)
616*38fd1498Szrj { return __rhs < __lhs; }
617*38fd1498Szrj
618*38fd1498Szrj template<typename _Key, typename _Compare, typename _Allocator>
619*38fd1498Szrj void
620*38fd1498Szrj swap(set<_Key, _Compare, _Allocator>& __x,
621*38fd1498Szrj set<_Key, _Compare, _Allocator>& __y)
622*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
623*38fd1498Szrj { return __x.swap(__y); }
624*38fd1498Szrj
625*38fd1498Szrj } // namespace __profile
626*38fd1498Szrj } // namespace std
627*38fd1498Szrj
628*38fd1498Szrj #endif
629