OSDN Git Service

merge branch profile-stdlib
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / profile / deque
1 // Profiling deque implementation -*- C++ -*-
2
3 // Copyright (C) 2009 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.
10
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.
15
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.
19
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/>.
24
25 /** @file profile/deque
26  *  This file is a GNU profile extension to the Standard C++ Library.
27  */
28
29 #ifndef _GLIBCXX_PROFILE_DEQUE
30 #define _GLIBCXX_PROFILE_DEQUE 1
31
32 #include <deque>
33
34 namespace std
35 {
36 namespace __profile
37 {
38   /** @brief Deque wrapper with performance instrumentation.  */
39   template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
40     class deque
41     : public _GLIBCXX_STD_D::deque<_Tp, _Allocator>
42     {
43       typedef  _GLIBCXX_STD_D::deque<_Tp, _Allocator> _Base;
44
45     public:
46       typedef typename _Base::reference             reference;
47       typedef typename _Base::const_reference       const_reference;
48
49       typedef typename _Base::iterator             iterator;
50       typedef typename _Base::const_iterator       const_iterator;
51       typedef typename _Base::reverse_iterator     reverse_iterator;
52       typedef typename _Base::const_reverse_iterator const_reverse_iterator;
53
54       typedef typename _Base::size_type             size_type;
55       typedef typename _Base::difference_type       difference_type;
56
57       typedef _Tp                                   value_type;
58       typedef _Allocator                            allocator_type;
59       typedef typename _Base::pointer               pointer;
60       typedef typename _Base::const_pointer         const_pointer;
61
62       // 23.2.1.1 construct/copy/destroy:
63       explicit deque(const _Allocator& __a = _Allocator())
64       : _Base(__a) { }
65
66       explicit deque(size_type __n, const _Tp& __value = _Tp(),
67                      const _Allocator& __a = _Allocator())
68       : _Base(__n, __value, __a) { }
69
70       template<class _InputIterator>
71         deque(_InputIterator __first, _InputIterator __last,
72               const _Allocator& __a = _Allocator())
73         : _Base(__first, __last, __a)
74         { }
75
76       deque(const deque& __x)
77       : _Base(__x) { }
78
79       deque(const _Base& __x)
80       : _Base(__x) { }
81
82 #ifdef __GXX_EXPERIMENTAL_CXX0X__
83       deque(deque&& __x)
84       : _Base(std::forward<deque>(__x))
85       { }
86
87       deque(initializer_list<value_type> __l,
88             const allocator_type& __a = allocator_type())
89       : _Base(__l, __a) { }
90 #endif
91
92       ~deque() { }
93
94       deque&
95       operator=(const deque& __x)
96       {
97         *static_cast<_Base*>(this) = __x;
98         return *this;
99       }
100
101 #ifdef __GXX_EXPERIMENTAL_CXX0X__
102       deque&
103       operator=(deque&& __x)
104       {
105         // NB: DR 675.
106         this->clear();
107         this->swap(__x);          
108         return *this;
109       }
110
111       deque&
112       operator=(initializer_list<value_type> __l)
113       {
114         *static_cast<_Base*>(this) = __l;
115         return *this;
116       }
117 #endif
118
119       template<class _InputIterator>
120         void
121         assign(_InputIterator __first, _InputIterator __last)
122         {
123           _Base::assign(__first, __last);
124         }
125
126       void
127       assign(size_type __n, const _Tp& __t)
128       {
129         _Base::assign(__n, __t);
130       }
131
132 #ifdef __GXX_EXPERIMENTAL_CXX0X__
133       void
134       assign(initializer_list<value_type> __l)
135       {
136         _Base::assign(__l);
137       }
138 #endif
139
140       using _Base::get_allocator;
141
142       // iterators:
143       iterator
144       begin()
145       { return iterator(_Base::begin()); }
146
147       const_iterator
148       begin() const
149       { return const_iterator(_Base::begin()); }
150
151       iterator
152       end()
153       { return iterator(_Base::end()); }
154
155       const_iterator
156       end() const
157       { return const_iterator(_Base::end()); }
158
159       reverse_iterator
160       rbegin()
161       { return reverse_iterator(end()); }
162
163       const_reverse_iterator
164       rbegin() const
165       { return const_reverse_iterator(end()); }
166
167       reverse_iterator
168       rend()
169       { return reverse_iterator(begin()); }
170
171       const_reverse_iterator
172       rend() const
173       { return const_reverse_iterator(begin()); }
174
175 #ifdef __GXX_EXPERIMENTAL_CXX0X__
176       const_iterator
177       cbegin() const
178       { return const_iterator(_Base::begin()); }
179
180       const_iterator
181       cend() const
182       { return const_iterator(_Base::end()); }
183
184       const_reverse_iterator
185       crbegin() const
186       { return const_reverse_iterator(end()); }
187
188       const_reverse_iterator
189       crend() const
190       { return const_reverse_iterator(begin()); }
191 #endif
192
193       // 23.2.1.2 capacity:
194       using _Base::size;
195       using _Base::max_size;
196
197       void
198       resize(size_type __sz, _Tp __c = _Tp())
199       {
200         _Base::resize(__sz, __c);
201       }
202
203       using _Base::empty;
204
205       // element access:
206       reference
207       operator[](size_type __n)
208       {
209         return _M_base()[__n];
210       }
211
212       const_reference
213       operator[](size_type __n) const
214       {
215         return _M_base()[__n];
216       }
217
218       using _Base::at;
219
220       reference
221       front()
222       {
223         return _Base::front();
224       }
225
226       const_reference
227       front() const
228       {
229         return _Base::front();
230       }
231
232       reference
233       back()
234       {
235         return _Base::back();
236       }
237
238       const_reference
239       back() const
240       {
241         return _Base::back();
242       }
243
244       // 23.2.1.3 modifiers:
245       void
246       push_front(const _Tp& __x)
247       {
248         _Base::push_front(__x);
249       }
250
251       void
252       push_back(const _Tp& __x)
253       {
254         _Base::push_back(__x);
255       }
256
257 #ifdef __GXX_EXPERIMENTAL_CXX0X__
258       void
259       push_front(_Tp&& __x)
260       { emplace_front(std::move(__x)); }
261
262       void
263       push_back(_Tp&& __x)
264       { emplace_back(std::move(__x)); }
265
266       template<typename... _Args>
267         void
268         emplace_front(_Args&&... __args)
269         {
270           _Base::emplace_front(std::forward<_Args>(__args)...);
271         }
272
273       template<typename... _Args>
274         void
275         emplace_back(_Args&&... __args)
276         {
277           _Base::emplace_back(std::forward<_Args>(__args)...);
278         }
279
280       template<typename... _Args>
281         iterator
282         emplace(iterator __position, _Args&&... __args)
283         {
284           typename _Base::iterator __res = _Base::emplace(__position,
285                                             std::forward<_Args>(__args)...);
286           return iterator(__res);
287         }
288 #endif
289
290       iterator
291       insert(iterator __position, const _Tp& __x)
292       {
293         typename _Base::iterator __res = _Base::insert(__position, __x);
294         return iterator(__res);
295       }
296
297 #ifdef __GXX_EXPERIMENTAL_CXX0X__
298       iterator
299       insert(iterator __position, _Tp&& __x)
300       { return emplace(__position, std::move(__x)); }
301
302       void
303       insert(iterator __p, initializer_list<value_type> __l)
304       {
305         _Base::insert(__p, __l);
306       }
307 #endif
308
309       void
310       insert(iterator __position, size_type __n, const _Tp& __x)
311       {
312         _Base::insert(__position, __n, __x);
313       }
314
315       template<class _InputIterator>
316         void
317         insert(iterator __position,
318                _InputIterator __first, _InputIterator __last)
319         {
320           _Base::insert(__position, __first, __last);
321         }
322
323       void
324       pop_front()
325       {
326         _Base::pop_front();
327       }
328
329       void
330       pop_back()
331       {
332         _Base::pop_back();
333       }
334
335       iterator
336       erase(iterator __position)
337       {
338         if (__position == begin() || __position == end()-1)
339           {
340             return iterator(_Base::erase(__position));
341           }
342         else
343           {
344             typename _Base::iterator __res = _Base::erase(__position);
345             return iterator(__res);
346           }
347       }
348
349       iterator
350       erase(iterator __first, iterator __last)
351       {
352         // _GLIBCXX_RESOLVE_LIB_DEFECTS
353         // 151. can't currently clear() empty container
354         return iterator(_Base::erase(__first, __last));
355       }
356
357       void
358       swap(deque& __x)
359       {
360         _Base::swap(__x);
361       }
362
363       void
364       clear()
365       {
366         _Base::clear();
367       }
368
369       _Base&
370       _M_base()       { return *this; }
371
372       const _Base&
373       _M_base() const { return *this; }
374     };
375
376   template<typename _Tp, typename _Alloc>
377     inline bool
378     operator==(const deque<_Tp, _Alloc>& __lhs,
379                const deque<_Tp, _Alloc>& __rhs)
380     { return __lhs._M_base() == __rhs._M_base(); }
381
382   template<typename _Tp, typename _Alloc>
383     inline bool
384     operator!=(const deque<_Tp, _Alloc>& __lhs,
385                const deque<_Tp, _Alloc>& __rhs)
386     { return __lhs._M_base() != __rhs._M_base(); }
387
388   template<typename _Tp, typename _Alloc>
389     inline bool
390     operator<(const deque<_Tp, _Alloc>& __lhs,
391               const deque<_Tp, _Alloc>& __rhs)
392     { return __lhs._M_base() < __rhs._M_base(); }
393
394   template<typename _Tp, typename _Alloc>
395     inline bool
396     operator<=(const deque<_Tp, _Alloc>& __lhs,
397                const deque<_Tp, _Alloc>& __rhs)
398     { return __lhs._M_base() <= __rhs._M_base(); }
399
400   template<typename _Tp, typename _Alloc>
401     inline bool
402     operator>=(const deque<_Tp, _Alloc>& __lhs,
403                const deque<_Tp, _Alloc>& __rhs)
404     { return __lhs._M_base() >= __rhs._M_base(); }
405
406   template<typename _Tp, typename _Alloc>
407     inline bool
408     operator>(const deque<_Tp, _Alloc>& __lhs,
409               const deque<_Tp, _Alloc>& __rhs)
410     { return __lhs._M_base() > __rhs._M_base(); }
411
412   template<typename _Tp, typename _Alloc>
413     inline void
414     swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
415     { __lhs.swap(__rhs); }
416
417 } // namespace __profile
418 } // namespace std
419
420 #endif