libstdc++
profile/deque
Go to the documentation of this file.
1 // Profiling deque implementation -*- C++ -*-
2 
3 // Copyright (C) 2009-2014 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 _GLIBCXX_VISIBILITY(default)
35 {
36 namespace __profile
37 {
38  /// Class std::deque wrapper with performance instrumentation.
39  template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
40  class deque
41  : public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
42  {
43  typedef _GLIBCXX_STD_C::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
64  deque(const _Allocator& __a = _Allocator())
65  : _Base(__a) { }
66 
67 #if __cplusplus >= 201103L
68  explicit
69  deque(size_type __n)
70  : _Base(__n) { }
71 
72  deque(size_type __n, const _Tp& __value,
73  const _Allocator& __a = _Allocator())
74  : _Base(__n, __value, __a) { }
75 #else
76  explicit
77  deque(size_type __n, const _Tp& __value = _Tp(),
78  const _Allocator& __a = _Allocator())
79  : _Base(__n, __value, __a) { }
80 #endif
81 
82 #if __cplusplus >= 201103L
83  template<typename _InputIterator,
84  typename = std::_RequireInputIter<_InputIterator>>
85 #else
86  template<typename _InputIterator>
87 #endif
88  deque(_InputIterator __first, _InputIterator __last,
89  const _Allocator& __a = _Allocator())
90  : _Base(__first, __last, __a)
91  { }
92 
93  deque(const deque& __x)
94  : _Base(__x) { }
95 
96  deque(const _Base& __x)
97  : _Base(__x) { }
98 
99 #if __cplusplus >= 201103L
100  deque(deque&& __x)
101  : _Base(std::move(__x))
102  { }
103 
105  const allocator_type& __a = allocator_type())
106  : _Base(__l, __a) { }
107 #endif
108 
109  ~deque() _GLIBCXX_NOEXCEPT { }
110 
111  deque&
112  operator=(const deque& __x)
113  {
114  *static_cast<_Base*>(this) = __x;
115  return *this;
116  }
117 
118 #if __cplusplus >= 201103L
119  deque&
120  operator=(deque&& __x) noexcept
121  {
122  // NB: DR 1204.
123  // NB: DR 675.
124  this->clear();
125  this->swap(__x);
126  return *this;
127  }
128 
129  deque&
130  operator=(initializer_list<value_type> __l)
131  {
132  *static_cast<_Base*>(this) = __l;
133  return *this;
134  }
135 #endif
136 
137 #if __cplusplus >= 201103L
138  template<typename _InputIterator,
139  typename = std::_RequireInputIter<_InputIterator>>
140 #else
141  template<typename _InputIterator>
142 #endif
143  void
144  assign(_InputIterator __first, _InputIterator __last)
145  {
146  _Base::assign(__first, __last);
147  }
148 
149  void
150  assign(size_type __n, const _Tp& __t)
151  {
152  _Base::assign(__n, __t);
153  }
154 
155 #if __cplusplus >= 201103L
156  void
157  assign(initializer_list<value_type> __l)
158  {
159  _Base::assign(__l);
160  }
161 #endif
162 
163  using _Base::get_allocator;
164 
165  // iterators:
166  iterator
167  begin() _GLIBCXX_NOEXCEPT
168  { return iterator(_Base::begin()); }
169 
170  const_iterator
171  begin() const _GLIBCXX_NOEXCEPT
172  { return const_iterator(_Base::begin()); }
173 
174  iterator
175  end() _GLIBCXX_NOEXCEPT
176  { return iterator(_Base::end()); }
177 
178  const_iterator
179  end() const _GLIBCXX_NOEXCEPT
180  { return const_iterator(_Base::end()); }
181 
182  reverse_iterator
183  rbegin() _GLIBCXX_NOEXCEPT
184  { return reverse_iterator(end()); }
185 
186  const_reverse_iterator
187  rbegin() const _GLIBCXX_NOEXCEPT
188  { return const_reverse_iterator(end()); }
189 
190  reverse_iterator
191  rend() _GLIBCXX_NOEXCEPT
192  { return reverse_iterator(begin()); }
193 
194  const_reverse_iterator
195  rend() const _GLIBCXX_NOEXCEPT
196  { return const_reverse_iterator(begin()); }
197 
198 #if __cplusplus >= 201103L
199  const_iterator
200  cbegin() const noexcept
201  { return const_iterator(_Base::begin()); }
202 
203  const_iterator
204  cend() const noexcept
205  { return const_iterator(_Base::end()); }
206 
207  const_reverse_iterator
208  crbegin() const noexcept
209  { return const_reverse_iterator(end()); }
210 
211  const_reverse_iterator
212  crend() const noexcept
213  { return const_reverse_iterator(begin()); }
214 #endif
215 
216  // 23.2.1.2 capacity:
217  using _Base::size;
218  using _Base::max_size;
219 
220 #if __cplusplus >= 201103L
221  void
222  resize(size_type __sz)
223  {
224  _Base::resize(__sz);
225  }
226 
227  void
228  resize(size_type __sz, const _Tp& __c)
229  {
230  _Base::resize(__sz, __c);
231  }
232 #else
233  void
234  resize(size_type __sz, _Tp __c = _Tp())
235  {
236  _Base::resize(__sz, __c);
237  }
238 #endif
239 
240 #if __cplusplus >= 201103L
241  using _Base::shrink_to_fit;
242 #endif
243 
244  using _Base::empty;
245 
246  // element access:
247  reference
248  operator[](size_type __n) _GLIBCXX_NOEXCEPT
249  {
250  return _M_base()[__n];
251  }
252 
253  const_reference
254  operator[](size_type __n) const _GLIBCXX_NOEXCEPT
255  {
256  return _M_base()[__n];
257  }
258 
259  using _Base::at;
260 
261  reference
262  front() _GLIBCXX_NOEXCEPT
263  {
264  return _Base::front();
265  }
266 
267  const_reference
268  front() const _GLIBCXX_NOEXCEPT
269  {
270  return _Base::front();
271  }
272 
273  reference
274  back() _GLIBCXX_NOEXCEPT
275  {
276  return _Base::back();
277  }
278 
279  const_reference
280  back() const _GLIBCXX_NOEXCEPT
281  {
282  return _Base::back();
283  }
284 
285  // 23.2.1.3 modifiers:
286  void
287  push_front(const _Tp& __x)
288  {
289  _Base::push_front(__x);
290  }
291 
292  void
293  push_back(const _Tp& __x)
294  {
295  _Base::push_back(__x);
296  }
297 
298 #if __cplusplus >= 201103L
299  void
300  push_front(_Tp&& __x)
301  { emplace_front(std::move(__x)); }
302 
303  void
304  push_back(_Tp&& __x)
305  { emplace_back(std::move(__x)); }
306 
307  template<typename... _Args>
308  void
309  emplace_front(_Args&&... __args)
310  {
311  _Base::emplace_front(std::forward<_Args>(__args)...);
312  }
313 
314  template<typename... _Args>
315  void
316  emplace_back(_Args&&... __args)
317  {
318  _Base::emplace_back(std::forward<_Args>(__args)...);
319  }
320 
321  template<typename... _Args>
322  iterator
323  emplace(const_iterator __position, _Args&&... __args)
324  {
325  typename _Base::iterator __res = _Base::emplace(__position,
326  std::forward<_Args>(__args)...);
327  return iterator(__res);
328  }
329 #endif
330 
331  iterator
332 #if __cplusplus >= 201103L
333  insert(const_iterator __position, const _Tp& __x)
334 #else
335  insert(iterator __position, const _Tp& __x)
336 #endif
337  {
338  typename _Base::iterator __res = _Base::insert(__position, __x);
339  return iterator(__res);
340  }
341 
342 #if __cplusplus >= 201103L
343  iterator
344  insert(const_iterator __position, _Tp&& __x)
345  { return emplace(__position, std::move(__x)); }
346 
347  iterator
348  insert(const_iterator __p, initializer_list<value_type> __l)
349  { return _Base::insert(__p, __l); }
350 #endif
351 
352 #if __cplusplus >= 201103L
353  iterator
354  insert(const_iterator __position, size_type __n, const _Tp& __x)
355  { return _Base::insert(__position, __n, __x); }
356 #else
357  void
358  insert(iterator __position, size_type __n, const _Tp& __x)
359  { _Base::insert(__position, __n, __x); }
360 #endif
361 
362 #if __cplusplus >= 201103L
363  template<typename _InputIterator,
364  typename = std::_RequireInputIter<_InputIterator>>
365  iterator
366  insert(const_iterator __position,
367  _InputIterator __first, _InputIterator __last)
368  { return _Base::insert(__position, __first, __last); }
369 #else
370  template<typename _InputIterator>
371  void
372  insert(iterator __position,
373  _InputIterator __first, _InputIterator __last)
374  { _Base::insert(__position, __first, __last); }
375 #endif
376 
377  void
378  pop_front() _GLIBCXX_NOEXCEPT
379  {
380  _Base::pop_front();
381  }
382 
383  void
384  pop_back() _GLIBCXX_NOEXCEPT
385  {
386  _Base::pop_back();
387  }
388 
389  iterator
390 #if __cplusplus >= 201103L
391  erase(const_iterator __position)
392 #else
393  erase(iterator __position)
394 #endif
395  {
396  return _Base::erase(__position);
397  }
398 
399  iterator
400 #if __cplusplus >= 201103L
401  erase(const_iterator __first, const_iterator __last)
402 #else
403  erase(iterator __first, iterator __last)
404 #endif
405  {
406  // _GLIBCXX_RESOLVE_LIB_DEFECTS
407  // 151. can't currently clear() empty container
408  return _Base::erase(__first, __last);
409  }
410 
411  void
412  swap(deque& __x) _GLIBCXX_NOEXCEPT
413  {
414  _Base::swap(__x);
415  }
416 
417  void
418  clear() _GLIBCXX_NOEXCEPT
419  {
420  _Base::clear();
421  }
422 
423  _Base&
424  _M_base() _GLIBCXX_NOEXCEPT { return *this; }
425 
426  const _Base&
427  _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
428  };
429 
430  template<typename _Tp, typename _Alloc>
431  inline bool
432  operator==(const deque<_Tp, _Alloc>& __lhs,
433  const deque<_Tp, _Alloc>& __rhs)
434  { return __lhs._M_base() == __rhs._M_base(); }
435 
436  template<typename _Tp, typename _Alloc>
437  inline bool
438  operator!=(const deque<_Tp, _Alloc>& __lhs,
439  const deque<_Tp, _Alloc>& __rhs)
440  { return __lhs._M_base() != __rhs._M_base(); }
441 
442  template<typename _Tp, typename _Alloc>
443  inline bool
444  operator<(const deque<_Tp, _Alloc>& __lhs,
445  const deque<_Tp, _Alloc>& __rhs)
446  { return __lhs._M_base() < __rhs._M_base(); }
447 
448  template<typename _Tp, typename _Alloc>
449  inline bool
450  operator<=(const deque<_Tp, _Alloc>& __lhs,
451  const deque<_Tp, _Alloc>& __rhs)
452  { return __lhs._M_base() <= __rhs._M_base(); }
453 
454  template<typename _Tp, typename _Alloc>
455  inline bool
456  operator>=(const deque<_Tp, _Alloc>& __lhs,
457  const deque<_Tp, _Alloc>& __rhs)
458  { return __lhs._M_base() >= __rhs._M_base(); }
459 
460  template<typename _Tp, typename _Alloc>
461  inline bool
462  operator>(const deque<_Tp, _Alloc>& __lhs,
463  const deque<_Tp, _Alloc>& __rhs)
464  { return __lhs._M_base() > __rhs._M_base(); }
465 
466  template<typename _Tp, typename _Alloc>
467  inline void
468  swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
469  { __lhs.swap(__rhs); }
470 
471 } // namespace __profile
472 } // namespace std
473 
474 #endif
Class std::deque wrapper with performance instrumentation.
Definition: profile/deque:40
constexpr size_t size() const noexcept
Returns the total number of bits.
Definition: bitset:1293
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
Definition: functional:2534
initializer_list
A standard container using fixed-size memory allocation and constant-time manipulation of elements at...
Definition: stl_deque.h:735