Merged with trunk at revision 155767
[official-gcc.git] / libstdc++-v3 / include / profile / list
blob09510a04205d1cf83b208421c3caaf1bc2957221
1 // Profiling list implementation -*- C++ -*-
3 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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/list
26  *  This file is a GNU profile extension to the Standard C++ Library.
27  */
29 #ifndef _GLIBCXX_PROFILE_LIST
30 #define _GLIBCXX_PROFILE_LIST 1
32 #include <list>
34 namespace std
36 namespace __profile
38   /// Class std::list wrapper with performance instrumentation.
39   template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
40     class list
41     : public _GLIBCXX_STD_D::list<_Tp, _Allocator>
42     {
43       typedef _GLIBCXX_STD_D::list<_Tp, _Allocator> _Base;
45     public:
46       typedef typename _Base::reference             reference;
47       typedef typename _Base::const_reference       const_reference;
49       typedef typename _Base::iterator              iterator;
50       typedef typename _Base::const_iterator        const_iterator;
52       typedef typename _Base::size_type             size_type;
53       typedef typename _Base::difference_type       difference_type;
55       typedef _Tp                                   value_type;
56       typedef _Allocator                            allocator_type;
57       typedef typename _Base::pointer               pointer;
58       typedef typename _Base::const_pointer         const_pointer;
59       typedef std::reverse_iterator<iterator>       reverse_iterator;
60       typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
62       // 23.2.2.1 construct/copy/destroy:
63       explicit list(const _Allocator& __a = _Allocator())
64       : _Base(__a) { }
66       explicit list(size_type __n, const _Tp& __value = _Tp(),
67                     const _Allocator& __a = _Allocator())
68       : _Base(__n, __value, __a) { }
70       template<class _InputIterator>
71       list(_InputIterator __first, _InputIterator __last,
72            const _Allocator& __a = _Allocator())
73       : _Base(__first, __last, __a)
74       { }
76       list(const list& __x)
77       : _Base(__x) { }
79       list(const _Base& __x)
80       : _Base(__x) { }
82 #ifdef __GXX_EXPERIMENTAL_CXX0X__
83       list(list&& __x)
84       : _Base(std::forward<list>(__x))
85       { }
87       list(initializer_list<value_type> __l,
88            const allocator_type& __a = allocator_type())
89         : _Base(__l, __a) { }
90 #endif
92       ~list() { }
94       list&
95       operator=(const list& __x)
96       {
97         static_cast<_Base&>(*this) = __x;
98         return *this;
99       }
101 #ifdef __GXX_EXPERIMENTAL_CXX0X__
102       list&
103       operator=(list&& __x)
104       {
105         // NB: DR 1204.
106         // NB: DR 675.
107         this->clear();
108         this->swap(__x);
109         return *this;
110       }
112       list&
113       operator=(initializer_list<value_type> __l)
114       {
115         static_cast<_Base&>(*this) = __l;
116         return *this;
117       }
119       void
120       assign(initializer_list<value_type> __l)
121       { _Base::assign(__l); }
122 #endif
124       template<class _InputIterator>
125         void
126         assign(_InputIterator __first, _InputIterator __last)
127         { _Base::assign(__first, __last); }
129       void
130       assign(size_type __n, const _Tp& __t)
131       { _Base::assign(__n, __t); }
133       using _Base::get_allocator;
135       // iterators:
136       iterator
137       begin()
138       { return iterator(_Base::begin()); }
140       const_iterator
141       begin() const
142       { return const_iterator(_Base::begin()); }
144       iterator
145       end()
146       { return iterator(_Base::end()); }
148       const_iterator
149       end() const
150       { return const_iterator(_Base::end()); }
152       reverse_iterator
153       rbegin()
154       { return reverse_iterator(end()); }
156       const_reverse_iterator
157       rbegin() const
158       { return const_reverse_iterator(end()); }
160       reverse_iterator
161       rend()
162       { return reverse_iterator(begin()); }
164       const_reverse_iterator
165       rend() const
166       { return const_reverse_iterator(begin()); }
168 #ifdef __GXX_EXPERIMENTAL_CXX0X__
169       const_iterator
170       cbegin() const
171       { return const_iterator(_Base::begin()); }
173       const_iterator
174       cend() const
175       { return const_iterator(_Base::end()); }
177       const_reverse_iterator
178       crbegin() const
179       { return const_reverse_iterator(end()); }
181       const_reverse_iterator
182       crend() const
183       { return const_reverse_iterator(begin()); }
184 #endif
186       // 23.2.2.2 capacity:
187       using _Base::empty;
188       using _Base::size;
189       using _Base::max_size;
191       void
192       resize(size_type __sz, _Tp __c = _Tp())
193       { _Base::resize(__sz, __c); }
195       // element access:
196       reference
197       front()
198       { return _Base::front(); }
200       const_reference
201       front() const
202       { return _Base::front(); }
204       reference
205       back()
206       { return _Base::back(); }
208       const_reference
209       back() const
210       { return _Base::back(); }
212       // 23.2.2.3 modifiers:
213       using _Base::push_front;
215 #ifdef __GXX_EXPERIMENTAL_CXX0X__
216       using _Base::emplace_front;
217 #endif
219       void
220       pop_front()
221       {
222         iterator __victim = begin();
223         _Base::pop_front();
224       }
226       using _Base::push_back;
228 #ifdef __GXX_EXPERIMENTAL_CXX0X__
229       using _Base::emplace_back;
230 #endif
232       void
233       pop_back()
234       {
235         iterator __victim = end();
236         --__victim;
237         _Base::pop_back();
238       }
240 #ifdef __GXX_EXPERIMENTAL_CXX0X__
241       template<typename... _Args>
242         iterator
243         emplace(iterator __position, _Args&&... __args)
244         {
245           return iterator(_Base::emplace(__position,
246                                         std::forward<_Args>(__args)...));
247         }
248 #endif
250       iterator
251       insert(iterator __position, const _Tp& __x)
252       { return iterator(_Base::insert(__position, __x)); }
254 #ifdef __GXX_EXPERIMENTAL_CXX0X__
255       iterator
256       insert(iterator __position, _Tp&& __x)
257       { return emplace(__position, std::move(__x)); }
259       void
260       insert(iterator __p, initializer_list<value_type> __l)
261       { _Base::insert(__p, __l); }
262 #endif
264       void
265       insert(iterator __position, size_type __n, const _Tp& __x)
266       { _Base::insert(__position, __n, __x); }
268       template<class _InputIterator>
269         void
270         insert(iterator __position, _InputIterator __first,
271                _InputIterator __last)
272         { _Base::insert(__position, __first, __last); }
274       iterator
275       erase(iterator __position)
276       { return iterator(_Base::erase(__position)); }
278       iterator
279       erase(iterator __position, iterator __last)
280       {
281         // _GLIBCXX_RESOLVE_LIB_DEFECTS
282         // 151. can't currently clear() empty container
283         return iterator(_Base::erase(__position, __last));
284       }
286       void
287       swap(list& __x)
288       { _Base::swap(__x); }
290       void
291       clear()
292       { _Base::clear(); }
294       // 23.2.2.4 list operations:
295       void
296 #ifdef __GXX_EXPERIMENTAL_CXX0X__
297       splice(iterator __position, list&& __x)
298 #else
299       splice(iterator __position, list& __x)
300 #endif
301       { this->splice(__position, _GLIBCXX_MOVE(__x), __x.begin(), __x.end()); }
303 #ifdef __GXX_EXPERIMENTAL_CXX0X__
304       void
305       splice(iterator __position, list& __x)
306       { this->splice(__position, std::move(__x)); }
307 #endif
309       void
310 #ifdef __GXX_EXPERIMENTAL_CXX0X__
311       splice(iterator __position, list&& __x, iterator __i)
312 #else
313       splice(iterator __position, list& __x, iterator __i)
314 #endif
315       {
316         // We used to perform the splice_alloc check:  not anymore, redundant
317         // after implementing the relevant bits of N1599.
319         // _GLIBCXX_RESOLVE_LIB_DEFECTS
320         _Base::splice(__position, _GLIBCXX_MOVE(__x._M_base()),
321                       __i);
322       }
324 #ifdef __GXX_EXPERIMENTAL_CXX0X__
325       void
326       splice(iterator __position, list& __x, iterator __i)
327       { this->splice(__position, std::move(__x), __i); }
328 #endif
330       void
331 #ifdef __GXX_EXPERIMENTAL_CXX0X__
332       splice(iterator __position, list&& __x, iterator __first,
333              iterator __last)
334 #else
335       splice(iterator __position, list& __x, iterator __first,
336              iterator __last)
337 #endif
338       {
339         // We used to perform the splice_alloc check:  not anymore, redundant
340         // after implementing the relevant bits of N1599.
342         _Base::splice(__position, _GLIBCXX_MOVE(__x._M_base()),
343                       __first, __last);
344       }
346 #ifdef __GXX_EXPERIMENTAL_CXX0X__
347       void
348       splice(iterator __position, list& __x, iterator __first, iterator __last)
349       { this->splice(__position, std::move(__x), __first, __last); }
350 #endif
352       void
353       remove(const _Tp& __value)
354       {
355         for (iterator __x = begin(); __x != _Base::end(); )
356           {
357             if (*__x == __value)
358               __x = erase(__x);
359             else
360               ++__x;
361           }
362       }
364       template<class _Predicate>
365         void
366         remove_if(_Predicate __pred)
367         {
368           for (iterator __x = begin(); __x != _Base::end(); )
369             {
370               if (__pred(*__x))
371                 __x = erase(__x);
372               else
373                 ++__x;
374             }
375         }
377       void
378       unique()
379       {
380         iterator __first = begin();
381         iterator __last = end();
382         if (__first == __last)
383           return;
384         iterator __next = __first;
385         while (++__next != __last)
386           {
387             if (*__first == *__next)
388               erase(__next);
389             else
390               __first = __next;
391             __next = __first;
392           }
393       }
395       template<class _BinaryPredicate>
396         void
397         unique(_BinaryPredicate __binary_pred)
398         {
399           iterator __first = begin();
400           iterator __last = end();
401           if (__first == __last)
402             return;
403           iterator __next = __first;
404           while (++__next != __last)
405             {
406               if (__binary_pred(*__first, *__next))
407                 erase(__next);
408               else
409                 __first = __next;
410               __next = __first;
411             }
412         }
414       void
415 #ifdef __GXX_EXPERIMENTAL_CXX0X__
416       merge(list&& __x)
417 #else
418       merge(list& __x)
419 #endif
420       {
421         // _GLIBCXX_RESOLVE_LIB_DEFECTS
422         // 300. list::merge() specification incomplete
423         if (this != &__x)
424           _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
425       }
427 #ifdef __GXX_EXPERIMENTAL_CXX0X__
428       void
429       merge(list& __x)
430       { this->merge(std::move(__x)); }
431 #endif
433       template<class _Compare>
434         void
435 #ifdef __GXX_EXPERIMENTAL_CXX0X__
436         merge(list&& __x, _Compare __comp)
437 #else
438         merge(list& __x, _Compare __comp)
439 #endif
440         {
441           // _GLIBCXX_RESOLVE_LIB_DEFECTS
442           // 300. list::merge() specification incomplete
443           if (this != &__x)
444             _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
445         }
447 #ifdef __GXX_EXPERIMENTAL_CXX0X__
448       template<typename _Compare>
449         void
450         merge(list& __x, _Compare __comp)
451         { this->merge(std::move(__x), __comp); }
452 #endif
454       void
455       sort() { _Base::sort(); }
457       template<typename _StrictWeakOrdering>
458         void
459         sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
461       using _Base::reverse;
463       _Base&
464       _M_base()       { return *this; }
466       const _Base&
467       _M_base() const { return *this; }
469     };
471   template<typename _Tp, typename _Alloc>
472     inline bool
473     operator==(const list<_Tp, _Alloc>& __lhs,
474                const list<_Tp, _Alloc>& __rhs)
475     { return __lhs._M_base() == __rhs._M_base(); }
477   template<typename _Tp, typename _Alloc>
478     inline bool
479     operator!=(const list<_Tp, _Alloc>& __lhs,
480                const list<_Tp, _Alloc>& __rhs)
481     { return __lhs._M_base() != __rhs._M_base(); }
483   template<typename _Tp, typename _Alloc>
484     inline bool
485     operator<(const list<_Tp, _Alloc>& __lhs,
486               const list<_Tp, _Alloc>& __rhs)
487     { return __lhs._M_base() < __rhs._M_base(); }
489   template<typename _Tp, typename _Alloc>
490     inline bool
491     operator<=(const list<_Tp, _Alloc>& __lhs,
492                const list<_Tp, _Alloc>& __rhs)
493     { return __lhs._M_base() <= __rhs._M_base(); }
495   template<typename _Tp, typename _Alloc>
496     inline bool
497     operator>=(const list<_Tp, _Alloc>& __lhs,
498                const list<_Tp, _Alloc>& __rhs)
499     { return __lhs._M_base() >= __rhs._M_base(); }
501   template<typename _Tp, typename _Alloc>
502     inline bool
503     operator>(const list<_Tp, _Alloc>& __lhs,
504               const list<_Tp, _Alloc>& __rhs)
505     { return __lhs._M_base() > __rhs._M_base(); }
507   template<typename _Tp, typename _Alloc>
508     inline void
509     swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
510     { __lhs.swap(__rhs); }
512 } // namespace __profile
513 } // namespace std
515 #endif