1 // Profiling deque 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/deque
26 * This file is a GNU profile extension to the Standard C++ Library.
29 #ifndef _GLIBCXX_PROFILE_DEQUE
30 #define _GLIBCXX_PROFILE_DEQUE 1
38 /// Class std::deque wrapper with performance instrumentation.
39 template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
41 : public _GLIBCXX_STD_D::deque<_Tp, _Allocator>
43 typedef _GLIBCXX_STD_D::deque<_Tp, _Allocator> _Base;
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;
51 typedef typename _Base::reverse_iterator reverse_iterator;
52 typedef typename _Base::const_reverse_iterator const_reverse_iterator;
54 typedef typename _Base::size_type size_type;
55 typedef typename _Base::difference_type difference_type;
57 typedef _Tp value_type;
58 typedef _Allocator allocator_type;
59 typedef typename _Base::pointer pointer;
60 typedef typename _Base::const_pointer const_pointer;
62 // 23.2.1.1 construct/copy/destroy:
64 deque(const _Allocator& __a = _Allocator())
67 #ifdef __GXX_EXPERIMENTAL_CXX0X__
72 deque(size_type __n, const _Tp& __value,
73 const _Allocator& __a = _Allocator())
74 : _Base(__n, __value, __a) { }
77 deque(size_type __n, const _Tp& __value = _Tp(),
78 const _Allocator& __a = _Allocator())
79 : _Base(__n, __value, __a) { }
82 template<class _InputIterator>
83 deque(_InputIterator __first, _InputIterator __last,
84 const _Allocator& __a = _Allocator())
85 : _Base(__first, __last, __a)
88 deque(const deque& __x)
91 deque(const _Base& __x)
94 #ifdef __GXX_EXPERIMENTAL_CXX0X__
96 : _Base(std::move(__x))
99 deque(initializer_list<value_type> __l,
100 const allocator_type& __a = allocator_type())
101 : _Base(__l, __a) { }
107 operator=(const deque& __x)
109 *static_cast<_Base*>(this) = __x;
113 #ifdef __GXX_EXPERIMENTAL_CXX0X__
115 operator=(deque&& __x)
125 operator=(initializer_list<value_type> __l)
127 *static_cast<_Base*>(this) = __l;
132 template<class _InputIterator>
134 assign(_InputIterator __first, _InputIterator __last)
136 _Base::assign(__first, __last);
140 assign(size_type __n, const _Tp& __t)
142 _Base::assign(__n, __t);
145 #ifdef __GXX_EXPERIMENTAL_CXX0X__
147 assign(initializer_list<value_type> __l)
153 using _Base::get_allocator;
158 { return iterator(_Base::begin()); }
162 { return const_iterator(_Base::begin()); }
166 { return iterator(_Base::end()); }
170 { return const_iterator(_Base::end()); }
174 { return reverse_iterator(end()); }
176 const_reverse_iterator
178 { return const_reverse_iterator(end()); }
182 { return reverse_iterator(begin()); }
184 const_reverse_iterator
186 { return const_reverse_iterator(begin()); }
188 #ifdef __GXX_EXPERIMENTAL_CXX0X__
191 { return const_iterator(_Base::begin()); }
195 { return const_iterator(_Base::end()); }
197 const_reverse_iterator
199 { return const_reverse_iterator(end()); }
201 const_reverse_iterator
203 { return const_reverse_iterator(begin()); }
206 // 23.2.1.2 capacity:
208 using _Base::max_size;
210 #ifdef __GXX_EXPERIMENTAL_CXX0X__
212 resize(size_type __sz)
218 resize(size_type __sz, const _Tp& __c)
220 _Base::resize(__sz, __c);
224 resize(size_type __sz, _Tp __c = _Tp())
226 _Base::resize(__sz, __c);
230 #ifdef __GXX_EXPERIMENTAL_CXX0X__
231 using _Base::shrink_to_fit;
238 operator[](size_type __n)
240 return _M_base()[__n];
244 operator[](size_type __n) const
246 return _M_base()[__n];
254 return _Base::front();
260 return _Base::front();
266 return _Base::back();
272 return _Base::back();
275 // 23.2.1.3 modifiers:
277 push_front(const _Tp& __x)
279 _Base::push_front(__x);
283 push_back(const _Tp& __x)
285 _Base::push_back(__x);
288 #ifdef __GXX_EXPERIMENTAL_CXX0X__
290 push_front(_Tp&& __x)
291 { emplace_front(std::move(__x)); }
295 { emplace_back(std::move(__x)); }
297 template<typename... _Args>
299 emplace_front(_Args&&... __args)
301 _Base::emplace_front(std::forward<_Args>(__args)...);
304 template<typename... _Args>
306 emplace_back(_Args&&... __args)
308 _Base::emplace_back(std::forward<_Args>(__args)...);
311 template<typename... _Args>
313 emplace(iterator __position, _Args&&... __args)
315 typename _Base::iterator __res = _Base::emplace(__position,
316 std::forward<_Args>(__args)...);
317 return iterator(__res);
322 insert(iterator __position, const _Tp& __x)
324 typename _Base::iterator __res = _Base::insert(__position, __x);
325 return iterator(__res);
328 #ifdef __GXX_EXPERIMENTAL_CXX0X__
330 insert(iterator __position, _Tp&& __x)
331 { return emplace(__position, std::move(__x)); }
334 insert(iterator __p, initializer_list<value_type> __l)
336 _Base::insert(__p, __l);
341 insert(iterator __position, size_type __n, const _Tp& __x)
343 _Base::insert(__position, __n, __x);
346 template<class _InputIterator>
348 insert(iterator __position,
349 _InputIterator __first, _InputIterator __last)
351 _Base::insert(__position, __first, __last);
367 erase(iterator __position)
369 if (__position == begin() || __position == end()-1)
371 return iterator(_Base::erase(__position));
375 typename _Base::iterator __res = _Base::erase(__position);
376 return iterator(__res);
381 erase(iterator __first, iterator __last)
383 // _GLIBCXX_RESOLVE_LIB_DEFECTS
384 // 151. can't currently clear() empty container
385 return iterator(_Base::erase(__first, __last));
401 _M_base() { return *this; }
404 _M_base() const { return *this; }
407 template<typename _Tp, typename _Alloc>
409 operator==(const deque<_Tp, _Alloc>& __lhs,
410 const deque<_Tp, _Alloc>& __rhs)
411 { return __lhs._M_base() == __rhs._M_base(); }
413 template<typename _Tp, typename _Alloc>
415 operator!=(const deque<_Tp, _Alloc>& __lhs,
416 const deque<_Tp, _Alloc>& __rhs)
417 { return __lhs._M_base() != __rhs._M_base(); }
419 template<typename _Tp, typename _Alloc>
421 operator<(const deque<_Tp, _Alloc>& __lhs,
422 const deque<_Tp, _Alloc>& __rhs)
423 { return __lhs._M_base() < __rhs._M_base(); }
425 template<typename _Tp, typename _Alloc>
427 operator<=(const deque<_Tp, _Alloc>& __lhs,
428 const deque<_Tp, _Alloc>& __rhs)
429 { return __lhs._M_base() <= __rhs._M_base(); }
431 template<typename _Tp, typename _Alloc>
433 operator>=(const deque<_Tp, _Alloc>& __lhs,
434 const deque<_Tp, _Alloc>& __rhs)
435 { return __lhs._M_base() >= __rhs._M_base(); }
437 template<typename _Tp, typename _Alloc>
439 operator>(const deque<_Tp, _Alloc>& __lhs,
440 const deque<_Tp, _Alloc>& __rhs)
441 { return __lhs._M_base() > __rhs._M_base(); }
443 template<typename _Tp, typename _Alloc>
445 swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
446 { __lhs.swap(__rhs); }
448 } // namespace __profile