# profile/deque

Go to the documentation of this file.

    00001 // Profiling deque implementation -*- C++ -*-
    00002
    00003 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 3, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // Under Section 7 of GPL version 3, you are granted additional
    00017 // permissions described in the GCC Runtime Library Exception, version
    00018 // 3.1, as published by the Free Software Foundation.
    00019
    00020 // You should have received a copy of the GNU General Public License and
    00021 // a copy of the GCC Runtime Library Exception along with this program;
    00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00023 // <http://www.gnu.org/licenses/>.
    00024
    00025 /** @file profile/deque
    00026  *  This file is a GNU profile extension to the Standard C++ Library.
    00027  */
    00028
    00029 #ifndef _GLIBCXX_PROFILE_DEQUE
    00030 #define _GLIBCXX_PROFILE_DEQUE 1
    00031
    00032 #include <deque>
    00033
    00034 namespace std
    00035 {
    00036 namespace __profile
    00037 {
    00038   /// Class std::deque wrapper with performance instrumentation.
    00039   template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
    00040     class deque
    00041     : public _GLIBCXX_STD_D::deque<_Tp, _Allocator>
    00042     {
    00043       typedef  _GLIBCXX_STD_D::deque<_Tp, _Allocator> _Base;
    00044
    00045     public:
    00046       typedef typename _Base::reference             reference;
    00047       typedef typename _Base::const_reference       const_reference;
    00048
    00049       typedef typename _Base::iterator             iterator;
    00050       typedef typename _Base::const_iterator       const_iterator;
    00051       typedef typename _Base::reverse_iterator     reverse_iterator;
    00052       typedef typename _Base::const_reverse_iterator const_reverse_iterator;
    00053
    00054       typedef typename _Base::size_type             size_type;
    00055       typedef typename _Base::difference_type       difference_type;
    00056
    00057       typedef _Tp                   value_type;
    00058       typedef _Allocator                allocator_type;
    00059       typedef typename _Base::pointer               pointer;
    00060       typedef typename _Base::const_pointer         const_pointer;
    00061
    00062       // 23.2.1.1 construct/copy/destroy:
    00063       explicit deque(const _Allocator& __a = _Allocator())
    00064       : _Base(__a) { }
    00065
    00066       explicit deque(size_type __n, const _Tp& __value = _Tp(),
    00067              const _Allocator& __a = _Allocator())
    00068       : _Base(__n, __value, __a) { }
    00069
    00070       template<class _InputIterator>
    00071         deque(_InputIterator __first, _InputIterator __last,
    00072           const _Allocator& __a = _Allocator())
    00073     : _Base(__first, __last, __a)
    00074         { }
    00075
    00076       deque(const deque& __x)
    00077       : _Base(__x) { }
    00078
    00079       deque(const _Base& __x)
    00080       : _Base(__x) { }
    00081
    00082 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00083       deque(deque&& __x)
    00084       : _Base(std::forward<deque>(__x))
    00085       { }
    00086
    00087       deque(initializer_list<value_type> __l,
    00088         const allocator_type& __a = allocator_type())
    00089       : _Base(__l, __a) { }
    00090 #endif
    00091
    00092       ~deque() { }
    00093
    00094       deque&
    00095       operator=(const deque& __x)
    00096       {
    00097     *static_cast<_Base*>(this) = __x;
    00098     return *this;
    00099       }
    00100
    00101 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00102       deque&
    00103       operator=(deque&& __x)
    00104       {
    00105     // NB: DR 1204.
    00106     // NB: DR 675.
    00107     this->clear();
    00108     this->swap(__x);
    00109     return *this;
    00110       }
    00111
    00112       deque&
    00113       operator=(initializer_list<value_type> __l)
    00114       {
    00115     *static_cast<_Base*>(this) = __l;
    00116     return *this;
    00117       }
    00118 #endif
    00119
    00120       template<class _InputIterator>
    00121         void
    00122         assign(_InputIterator __first, _InputIterator __last)
    00123         {
    00124       _Base::assign(__first, __last);
    00125     }
    00126
    00127       void
    00128       assign(size_type __n, const _Tp& __t)
    00129       {
    00130     _Base::assign(__n, __t);
    00131       }
    00132
    00133 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00134       void
    00135       assign(initializer_list<value_type> __l)
    00136       {
    00137     _Base::assign(__l);
    00138       }
    00139 #endif
    00140
    00141       using _Base::get_allocator;
    00142
    00143       // iterators:
    00144       iterator
    00145       begin()
    00146       { return iterator(_Base::begin()); }
    00147
    00148       const_iterator
    00149       begin() const
    00150       { return const_iterator(_Base::begin()); }
    00151
    00152       iterator
    00153       end()
    00154       { return iterator(_Base::end()); }
    00155
    00156       const_iterator
    00157       end() const
    00158       { return const_iterator(_Base::end()); }
    00159
    00160       reverse_iterator
    00161       rbegin()
    00162       { return reverse_iterator(end()); }
    00163
    00164       const_reverse_iterator
    00165       rbegin() const
    00166       { return const_reverse_iterator(end()); }
    00167
    00168       reverse_iterator
    00169       rend()
    00170       { return reverse_iterator(begin()); }
    00171
    00172       const_reverse_iterator
    00173       rend() const
    00174       { return const_reverse_iterator(begin()); }
    00175
    00176 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00177       const_iterator
    00178       cbegin() const
    00179       { return const_iterator(_Base::begin()); }
    00180
    00181       const_iterator
    00182       cend() const
    00183       { return const_iterator(_Base::end()); }
    00184
    00185       const_reverse_iterator
    00186       crbegin() const
    00187       { return const_reverse_iterator(end()); }
    00188
    00189       const_reverse_iterator
    00190       crend() const
    00191       { return const_reverse_iterator(begin()); }
    00192 #endif
    00193
    00194       // 23.2.1.2 capacity:
    00195       using _Base::size;
    00196       using _Base::max_size;
    00197
    00198       void
    00199       resize(size_type __sz, _Tp __c = _Tp())
    00200       {
    00201     _Base::resize(__sz, __c);
    00202       }
    00203
    00204 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00205       using _Base::shrink_to_fit;
    00206 #endif
    00207
    00208       using _Base::empty;
    00209
    00210       // element access:
    00211       reference
    00212       operator[](size_type __n)
    00213       {
    00214     return _M_base()[__n];
    00215       }
    00216
    00217       const_reference
    00218       operator[](size_type __n) const
    00219       {
    00220     return _M_base()[__n];
    00221       }
    00222
    00223       using _Base::at;
    00224
    00225       reference
    00226       front()
    00227       {
    00228     return _Base::front();
    00229       }
    00230
    00231       const_reference
    00232       front() const
    00233       {
    00234     return _Base::front();
    00235       }
    00236
    00237       reference
    00238       back()
    00239       {
    00240     return _Base::back();
    00241       }
    00242
    00243       const_reference
    00244       back() const
    00245       {
    00246     return _Base::back();
    00247       }
    00248
    00249       // 23.2.1.3 modifiers:
    00250       void
    00251       push_front(const _Tp& __x)
    00252       {
    00253     _Base::push_front(__x);
    00254       }
    00255
    00256       void
    00257       push_back(const _Tp& __x)
    00258       {
    00259     _Base::push_back(__x);
    00260       }
    00261
    00262 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00263       void
    00264       push_front(_Tp&& __x)
    00265       { emplace_front(std::move(__x)); }
    00266
    00267       void
    00268       push_back(_Tp&& __x)
    00269       { emplace_back(std::move(__x)); }
    00270
    00271       template<typename... _Args>
    00272         void
    00273         emplace_front(_Args&&... __args)
    00274     {
    00275       _Base::emplace_front(std::forward<_Args>(__args)...);
    00276     }
    00277
    00278       template<typename... _Args>
    00279         void
    00280         emplace_back(_Args&&... __args)
    00281     {
    00282       _Base::emplace_back(std::forward<_Args>(__args)...);
    00283     }
    00284
    00285       template<typename... _Args>
    00286         iterator
    00287         emplace(iterator __position, _Args&&... __args)
    00288     {
    00289       typename _Base::iterator __res = _Base::emplace(__position,
    00290                         std::forward<_Args>(__args)...);
    00291       return iterator(__res);
    00292     }
    00293 #endif
    00294
    00295       iterator
    00296       insert(iterator __position, const _Tp& __x)
    00297       {
    00298     typename _Base::iterator __res = _Base::insert(__position, __x);
    00299     return iterator(__res);
    00300       }
    00301
    00302 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00303       iterator
    00304       insert(iterator __position, _Tp&& __x)
    00305       { return emplace(__position, std::move(__x)); }
    00306
    00307       void
    00308       insert(iterator __p, initializer_list<value_type> __l)
    00309       {
    00310     _Base::insert(__p, __l);
    00311       }
    00312 #endif
    00313
    00314       void
    00315       insert(iterator __position, size_type __n, const _Tp& __x)
    00316       {
    00317     _Base::insert(__position, __n, __x);
    00318       }
    00319
    00320       template<class _InputIterator>
    00321         void
    00322         insert(iterator __position,
    00323            _InputIterator __first, _InputIterator __last)
    00324         {
    00325       _Base::insert(__position, __first, __last);
    00326     }
    00327
    00328       void
    00329       pop_front()
    00330       {
    00331     _Base::pop_front();
    00332       }
    00333
    00334       void
    00335       pop_back()
    00336       {
    00337     _Base::pop_back();
    00338       }
    00339
    00340       iterator
    00341       erase(iterator __position)
    00342       {
    00343     if (__position == begin() || __position == end()-1)
    00344       {
    00345         return iterator(_Base::erase(__position));
    00346       }
    00347     else
    00348       {
    00349         typename _Base::iterator __res = _Base::erase(__position);
    00350         return iterator(__res);
    00351       }
    00352       }
    00353
    00354       iterator
    00355       erase(iterator __first, iterator __last)
    00356       {
    00357     // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00358     // 151. can't currently clear() empty container
    00359         return iterator(_Base::erase(__first, __last));
    00360       }
    00361
    00362       void
    00363       swap(deque& __x)
    00364       {
    00365     _Base::swap(__x);
    00366       }
    00367
    00368       void
    00369       clear()
    00370       {
    00371     _Base::clear();
    00372       }
    00373
    00374       _Base&
    00375       _M_base()       { return *this; }
    00376
    00377       const _Base&
    00378       _M_base() const { return *this; }
    00379     };
    00380
    00381   template<typename _Tp, typename _Alloc>
    00382     inline bool
    00383     operator==(const deque<_Tp, _Alloc>& __lhs,
    00384            const deque<_Tp, _Alloc>& __rhs)
    00385     { return __lhs._M_base() == __rhs._M_base(); }
    00386
    00387   template<typename _Tp, typename _Alloc>
    00388     inline bool
    00389     operator!=(const deque<_Tp, _Alloc>& __lhs,
    00390            const deque<_Tp, _Alloc>& __rhs)
    00391     { return __lhs._M_base() != __rhs._M_base(); }
    00392
    00393   template<typename _Tp, typename _Alloc>
    00394     inline bool
    00395     operator<(const deque<_Tp, _Alloc>& __lhs,
    00396           const deque<_Tp, _Alloc>& __rhs)
    00397     { return __lhs._M_base() < __rhs._M_base(); }
    00398
    00399   template<typename _Tp, typename _Alloc>
    00400     inline bool
    00401     operator<=(const deque<_Tp, _Alloc>& __lhs,
    00402            const deque<_Tp, _Alloc>& __rhs)
    00403     { return __lhs._M_base() <= __rhs._M_base(); }
    00404
    00405   template<typename _Tp, typename _Alloc>
    00406     inline bool
    00407     operator>=(const deque<_Tp, _Alloc>& __lhs,
    00408            const deque<_Tp, _Alloc>& __rhs)
    00409     { return __lhs._M_base() >= __rhs._M_base(); }
    00410
    00411   template<typename _Tp, typename _Alloc>
    00412     inline bool
    00413     operator>(const deque<_Tp, _Alloc>& __lhs,
    00414           const deque<_Tp, _Alloc>& __rhs)
    00415     { return __lhs._M_base() > __rhs._M_base(); }
    00416
    00417   template<typename _Tp, typename _Alloc>
    00418     inline void
    00419     swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
    00420     { __lhs.swap(__rhs); }
    00421
    00422 } // namespace __profile
    00423 } // namespace std
    00424
    00425 #endif