libstdc++
deque
Go to the documentation of this file.
00001 // Profiling deque implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2009-2014 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 _GLIBCXX_VISIBILITY(default)
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_C::deque<_Tp, _Allocator>
00042     {
00043       typedef  _GLIBCXX_STD_C::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 
00064       deque()
00065       : _Base() { }
00066 
00067       explicit
00068       deque(const _Allocator& __a)
00069       : _Base(__a) { }
00070 
00071 #if __cplusplus >= 201103L
00072       explicit
00073       deque(size_type __n)
00074       : _Base(__n) { }
00075 
00076       deque(size_type __n, const _Tp& __value,
00077         const _Allocator& __a = _Allocator())
00078       : _Base(__n, __value, __a) { }
00079 #else
00080       explicit
00081       deque(size_type __n, const _Tp& __value = _Tp(),
00082         const _Allocator& __a = _Allocator())
00083       : _Base(__n, __value, __a) { }
00084 #endif
00085 
00086 #if __cplusplus >= 201103L
00087       template<typename _InputIterator,
00088            typename = std::_RequireInputIter<_InputIterator>>
00089 #else
00090       template<typename _InputIterator>
00091 #endif
00092         deque(_InputIterator __first, _InputIterator __last,
00093           const _Allocator& __a = _Allocator())
00094     : _Base(__first, __last, __a)
00095         { }
00096 
00097       deque(const deque& __x)
00098       : _Base(__x) { }
00099 
00100       deque(const _Base& __x)
00101       : _Base(__x) { }
00102 
00103 #if __cplusplus >= 201103L
00104       deque(deque&& __x)
00105       : _Base(std::move(__x))
00106       { }
00107 
00108       deque(initializer_list<value_type> __l,
00109         const allocator_type& __a = allocator_type())
00110       : _Base(__l, __a) { }
00111 #endif
00112 
00113       ~deque() _GLIBCXX_NOEXCEPT { }
00114 
00115       deque&
00116       operator=(const deque& __x)
00117       {
00118     *static_cast<_Base*>(this) = __x;
00119     return *this;
00120       }
00121 
00122 #if __cplusplus >= 201103L
00123       deque&
00124       operator=(deque&& __x) noexcept
00125       {
00126     // NB: DR 1204.
00127     // NB: DR 675.
00128     this->clear();
00129     this->swap(__x);
00130     return *this;
00131       }
00132 
00133       deque&
00134       operator=(initializer_list<value_type> __l)
00135       {
00136     *static_cast<_Base*>(this) = __l;
00137     return *this;
00138       }
00139 #endif
00140 
00141 #if __cplusplus >= 201103L
00142       template<typename _InputIterator,
00143            typename = std::_RequireInputIter<_InputIterator>>
00144 #else
00145       template<typename _InputIterator>
00146 #endif
00147         void
00148         assign(_InputIterator __first, _InputIterator __last)
00149         {
00150       _Base::assign(__first, __last);
00151     }
00152 
00153       void
00154       assign(size_type __n, const _Tp& __t)
00155       {
00156     _Base::assign(__n, __t);
00157       }
00158 
00159 #if __cplusplus >= 201103L
00160       void
00161       assign(initializer_list<value_type> __l)
00162       {
00163     _Base::assign(__l);
00164       }
00165 #endif
00166 
00167       using _Base::get_allocator;
00168 
00169       // iterators:
00170       iterator
00171       begin() _GLIBCXX_NOEXCEPT
00172       { return iterator(_Base::begin()); }
00173 
00174       const_iterator
00175       begin() const _GLIBCXX_NOEXCEPT
00176       { return const_iterator(_Base::begin()); }
00177 
00178       iterator
00179       end() _GLIBCXX_NOEXCEPT
00180       { return iterator(_Base::end()); }
00181 
00182       const_iterator
00183       end() const _GLIBCXX_NOEXCEPT
00184       { return const_iterator(_Base::end()); }
00185 
00186       reverse_iterator
00187       rbegin() _GLIBCXX_NOEXCEPT
00188       { return reverse_iterator(end()); }
00189 
00190       const_reverse_iterator
00191       rbegin() const _GLIBCXX_NOEXCEPT
00192       { return const_reverse_iterator(end()); }
00193 
00194       reverse_iterator
00195       rend() _GLIBCXX_NOEXCEPT
00196       { return reverse_iterator(begin()); }
00197 
00198       const_reverse_iterator
00199       rend() const _GLIBCXX_NOEXCEPT
00200       { return const_reverse_iterator(begin()); }
00201 
00202 #if __cplusplus >= 201103L
00203       const_iterator
00204       cbegin() const noexcept
00205       { return const_iterator(_Base::begin()); }
00206 
00207       const_iterator
00208       cend() const noexcept
00209       { return const_iterator(_Base::end()); }
00210 
00211       const_reverse_iterator
00212       crbegin() const noexcept
00213       { return const_reverse_iterator(end()); }
00214 
00215       const_reverse_iterator
00216       crend() const noexcept
00217       { return const_reverse_iterator(begin()); }
00218 #endif
00219 
00220       // 23.2.1.2 capacity:
00221       using _Base::size;
00222       using _Base::max_size;
00223 
00224 #if __cplusplus >= 201103L
00225       void
00226       resize(size_type __sz)
00227       {
00228     _Base::resize(__sz);
00229       }
00230 
00231       void
00232       resize(size_type __sz, const _Tp& __c)
00233       {
00234     _Base::resize(__sz, __c);
00235       }
00236 #else
00237       void
00238       resize(size_type __sz, _Tp __c = _Tp())
00239       {
00240     _Base::resize(__sz, __c);
00241       }
00242 #endif
00243 
00244 #if __cplusplus >= 201103L
00245       using _Base::shrink_to_fit;
00246 #endif
00247 
00248       using _Base::empty;
00249 
00250       // element access:
00251       reference
00252       operator[](size_type __n) _GLIBCXX_NOEXCEPT
00253       {
00254     return _M_base()[__n];
00255       }
00256 
00257       const_reference
00258       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
00259       {
00260     return _M_base()[__n];
00261       }
00262 
00263       using _Base::at;
00264 
00265       reference
00266       front() _GLIBCXX_NOEXCEPT
00267       {
00268     return _Base::front();
00269       }
00270 
00271       const_reference
00272       front() const _GLIBCXX_NOEXCEPT
00273       {
00274     return _Base::front();
00275       }
00276 
00277       reference
00278       back() _GLIBCXX_NOEXCEPT
00279       {
00280     return _Base::back();
00281       }
00282 
00283       const_reference
00284       back() const _GLIBCXX_NOEXCEPT
00285       {
00286     return _Base::back();
00287       }
00288 
00289       // 23.2.1.3 modifiers:
00290       void
00291       push_front(const _Tp& __x)
00292       {
00293     _Base::push_front(__x);
00294       }
00295 
00296       void
00297       push_back(const _Tp& __x)
00298       {
00299     _Base::push_back(__x);
00300       }
00301 
00302 #if __cplusplus >= 201103L
00303       void
00304       push_front(_Tp&& __x)
00305       { emplace_front(std::move(__x)); }
00306 
00307       void
00308       push_back(_Tp&& __x)
00309       { emplace_back(std::move(__x)); }
00310 
00311       template<typename... _Args>
00312         void
00313         emplace_front(_Args&&... __args)
00314     {
00315       _Base::emplace_front(std::forward<_Args>(__args)...);
00316     }
00317 
00318       template<typename... _Args>
00319         void
00320         emplace_back(_Args&&... __args)
00321     {
00322       _Base::emplace_back(std::forward<_Args>(__args)...);
00323     }
00324 
00325       template<typename... _Args>
00326         iterator
00327         emplace(const_iterator __position, _Args&&... __args)
00328     {
00329       typename _Base::iterator __res = _Base::emplace(__position,
00330                         std::forward<_Args>(__args)...);
00331       return iterator(__res);
00332     }
00333 #endif
00334 
00335       iterator
00336 #if __cplusplus >= 201103L
00337       insert(const_iterator __position, const _Tp& __x)
00338 #else
00339       insert(iterator __position, const _Tp& __x)
00340 #endif
00341       {
00342     typename _Base::iterator __res = _Base::insert(__position, __x);
00343     return iterator(__res);
00344       }
00345 
00346 #if __cplusplus >= 201103L
00347       iterator
00348       insert(const_iterator __position, _Tp&& __x)
00349       { return emplace(__position, std::move(__x)); }
00350 
00351       iterator
00352       insert(const_iterator __p, initializer_list<value_type> __l)
00353       { return _Base::insert(__p, __l); }
00354 #endif
00355 
00356 #if __cplusplus >= 201103L
00357       iterator
00358       insert(const_iterator __position, size_type __n, const _Tp& __x)
00359       { return _Base::insert(__position, __n, __x); }
00360 #else
00361       void
00362       insert(iterator __position, size_type __n, const _Tp& __x)
00363       { _Base::insert(__position, __n, __x); }
00364 #endif
00365 
00366 #if __cplusplus >= 201103L
00367       template<typename _InputIterator,
00368            typename = std::_RequireInputIter<_InputIterator>>
00369         iterator
00370         insert(const_iterator __position,
00371            _InputIterator __first, _InputIterator __last)
00372         { return _Base::insert(__position, __first, __last); }
00373 #else
00374       template<typename _InputIterator>
00375         void
00376         insert(iterator __position,
00377            _InputIterator __first, _InputIterator __last)
00378         { _Base::insert(__position, __first, __last); }
00379 #endif
00380 
00381       void
00382       pop_front() _GLIBCXX_NOEXCEPT
00383       {
00384     _Base::pop_front();
00385       }
00386 
00387       void
00388       pop_back() _GLIBCXX_NOEXCEPT
00389       {
00390     _Base::pop_back();
00391       }
00392 
00393       iterator
00394 #if __cplusplus >= 201103L
00395       erase(const_iterator __position)
00396 #else
00397       erase(iterator __position)    
00398 #endif
00399       {
00400     return _Base::erase(__position);
00401       }
00402 
00403       iterator
00404 #if __cplusplus >= 201103L
00405       erase(const_iterator __first, const_iterator __last)
00406 #else
00407       erase(iterator __first, iterator __last)
00408 #endif
00409       {
00410     // _GLIBCXX_RESOLVE_LIB_DEFECTS
00411     // 151. can't currently clear() empty container
00412         return _Base::erase(__first, __last);
00413       }
00414 
00415       void
00416       swap(deque& __x) _GLIBCXX_NOEXCEPT
00417       {
00418     _Base::swap(__x);
00419       }
00420 
00421       void
00422       clear() _GLIBCXX_NOEXCEPT
00423       {
00424     _Base::clear();
00425       }
00426 
00427       _Base&
00428       _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
00429 
00430       const _Base&
00431       _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
00432     };
00433 
00434   template<typename _Tp, typename _Alloc>
00435     inline bool
00436     operator==(const deque<_Tp, _Alloc>& __lhs,
00437            const deque<_Tp, _Alloc>& __rhs)
00438     { return __lhs._M_base() == __rhs._M_base(); }
00439 
00440   template<typename _Tp, typename _Alloc>
00441     inline bool
00442     operator!=(const deque<_Tp, _Alloc>& __lhs,
00443            const deque<_Tp, _Alloc>& __rhs)
00444     { return __lhs._M_base() != __rhs._M_base(); }
00445 
00446   template<typename _Tp, typename _Alloc>
00447     inline bool
00448     operator<(const deque<_Tp, _Alloc>& __lhs,
00449           const deque<_Tp, _Alloc>& __rhs)
00450     { return __lhs._M_base() < __rhs._M_base(); }
00451 
00452   template<typename _Tp, typename _Alloc>
00453     inline bool
00454     operator<=(const deque<_Tp, _Alloc>& __lhs,
00455            const deque<_Tp, _Alloc>& __rhs)
00456     { return __lhs._M_base() <= __rhs._M_base(); }
00457 
00458   template<typename _Tp, typename _Alloc>
00459     inline bool
00460     operator>=(const deque<_Tp, _Alloc>& __lhs,
00461            const deque<_Tp, _Alloc>& __rhs)
00462     { return __lhs._M_base() >= __rhs._M_base(); }
00463 
00464   template<typename _Tp, typename _Alloc>
00465     inline bool
00466     operator>(const deque<_Tp, _Alloc>& __lhs,
00467           const deque<_Tp, _Alloc>& __rhs)
00468     { return __lhs._M_base() > __rhs._M_base(); }
00469 
00470   template<typename _Tp, typename _Alloc>
00471     inline void
00472     swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
00473     { __lhs.swap(__rhs); }
00474 
00475 } // namespace __profile
00476 } // namespace std
00477 
00478 #endif