1 // Profiling deque implementation -*- C++ -*-
 
    3 // Copyright (C) 2009-2014 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
 
   34 namespace std _GLIBCXX_VISIBILITY(default)
 
   38   /// Class std::deque wrapper with performance instrumentation.
 
   39   template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
 
   41     : public _GLIBCXX_STD_C::deque<_Tp, _Allocator>
 
   43       typedef  _GLIBCXX_STD_C::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:
 
   68       deque(const _Allocator& __a)
 
   71 #if __cplusplus >= 201103L
 
   76       deque(size_type __n, const _Tp& __value,
 
   77        const _Allocator& __a = _Allocator())
 
   78       : _Base(__n, __value, __a) { }
 
   81       deque(size_type __n, const _Tp& __value = _Tp(),
 
   82        const _Allocator& __a = _Allocator())
 
   83       : _Base(__n, __value, __a) { }
 
   86 #if __cplusplus >= 201103L
 
   87       template<typename _InputIterator,
 
   88           typename = std::_RequireInputIter<_InputIterator>>
 
   90       template<typename _InputIterator>
 
   92         deque(_InputIterator __first, _InputIterator __last,
 
   93          const _Allocator& __a = _Allocator())
 
   94    : _Base(__first, __last, __a)
 
   97       deque(const deque& __x)
 
  100       deque(const _Base& __x)
 
  103 #if __cplusplus >= 201103L
 
  105       : _Base(std::move(__x))
 
  108       deque(initializer_list<value_type> __l,
 
  109        const allocator_type& __a = allocator_type())
 
  110       : _Base(__l, __a) { }
 
  113       ~deque() _GLIBCXX_NOEXCEPT { }
 
  116       operator=(const deque& __x)
 
  118    *static_cast<_Base*>(this) = __x;
 
  122 #if __cplusplus >= 201103L
 
  124       operator=(deque&& __x) noexcept
 
  134       operator=(initializer_list<value_type> __l)
 
  136    *static_cast<_Base*>(this) = __l;
 
  141 #if __cplusplus >= 201103L
 
  142       template<typename _InputIterator,
 
  143           typename = std::_RequireInputIter<_InputIterator>>
 
  145       template<typename _InputIterator>
 
  148         assign(_InputIterator __first, _InputIterator __last)
 
  150      _Base::assign(__first, __last);
 
  154       assign(size_type __n, const _Tp& __t)
 
  156    _Base::assign(__n, __t);
 
  159 #if __cplusplus >= 201103L
 
  161       assign(initializer_list<value_type> __l)
 
  167       using _Base::get_allocator;
 
  171       begin() _GLIBCXX_NOEXCEPT
 
  172       { return iterator(_Base::begin()); }
 
  175       begin() const _GLIBCXX_NOEXCEPT
 
  176       { return const_iterator(_Base::begin()); }
 
  179       end() _GLIBCXX_NOEXCEPT
 
  180       { return iterator(_Base::end()); }
 
  183       end() const _GLIBCXX_NOEXCEPT
 
  184       { return const_iterator(_Base::end()); }
 
  187       rbegin() _GLIBCXX_NOEXCEPT
 
  188       { return reverse_iterator(end()); }
 
  190       const_reverse_iterator
 
  191       rbegin() const _GLIBCXX_NOEXCEPT
 
  192       { return const_reverse_iterator(end()); }
 
  195       rend() _GLIBCXX_NOEXCEPT
 
  196       { return reverse_iterator(begin()); }
 
  198       const_reverse_iterator
 
  199       rend() const _GLIBCXX_NOEXCEPT
 
  200       { return const_reverse_iterator(begin()); }
 
  202 #if __cplusplus >= 201103L
 
  204       cbegin() const noexcept
 
  205       { return const_iterator(_Base::begin()); }
 
  208       cend() const noexcept
 
  209       { return const_iterator(_Base::end()); }
 
  211       const_reverse_iterator
 
  212       crbegin() const noexcept
 
  213       { return const_reverse_iterator(end()); }
 
  215       const_reverse_iterator
 
  216       crend() const noexcept
 
  217       { return const_reverse_iterator(begin()); }
 
  220       // 23.2.1.2 capacity:
 
  222       using _Base::max_size;
 
  224 #if __cplusplus >= 201103L
 
  226       resize(size_type __sz)
 
  232       resize(size_type __sz, const _Tp& __c)
 
  234    _Base::resize(__sz, __c);
 
  238       resize(size_type __sz, _Tp __c = _Tp())
 
  240    _Base::resize(__sz, __c);
 
  244 #if __cplusplus >= 201103L
 
  245       using _Base::shrink_to_fit;
 
  252       operator[](size_type __n) _GLIBCXX_NOEXCEPT
 
  254    return _M_base()[__n];
 
  258       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
 
  260    return _M_base()[__n];
 
  266       front() _GLIBCXX_NOEXCEPT
 
  268    return _Base::front();
 
  272       front() const _GLIBCXX_NOEXCEPT
 
  274    return _Base::front();
 
  278       back() _GLIBCXX_NOEXCEPT
 
  280    return _Base::back();
 
  284       back() const _GLIBCXX_NOEXCEPT
 
  286    return _Base::back();
 
  289       // 23.2.1.3 modifiers:
 
  291       push_front(const _Tp& __x)
 
  293    _Base::push_front(__x);
 
  297       push_back(const _Tp& __x)
 
  299    _Base::push_back(__x);
 
  302 #if __cplusplus >= 201103L
 
  304       push_front(_Tp&& __x)
 
  305       { emplace_front(std::move(__x)); }
 
  309       { emplace_back(std::move(__x)); }
 
  311       template<typename... _Args>
 
  313         emplace_front(_Args&&... __args)
 
  315      _Base::emplace_front(std::forward<_Args>(__args)...);
 
  318       template<typename... _Args>
 
  320         emplace_back(_Args&&... __args)
 
  322      _Base::emplace_back(std::forward<_Args>(__args)...);
 
  325       template<typename... _Args>
 
  327         emplace(const_iterator __position, _Args&&... __args)
 
  329      typename _Base::iterator __res = _Base::emplace(__position,
 
  330                        std::forward<_Args>(__args)...);
 
  331      return iterator(__res);
 
  336 #if __cplusplus >= 201103L
 
  337       insert(const_iterator __position, const _Tp& __x)
 
  339       insert(iterator __position, const _Tp& __x)
 
  342    typename _Base::iterator __res = _Base::insert(__position, __x);
 
  343    return iterator(__res);
 
  346 #if __cplusplus >= 201103L
 
  348       insert(const_iterator __position, _Tp&& __x)
 
  349       { return emplace(__position, std::move(__x)); }
 
  352       insert(const_iterator __p, initializer_list<value_type> __l)
 
  353       { return _Base::insert(__p, __l); }
 
  356 #if __cplusplus >= 201103L
 
  358       insert(const_iterator __position, size_type __n, const _Tp& __x)
 
  359       { return _Base::insert(__position, __n, __x); }
 
  362       insert(iterator __position, size_type __n, const _Tp& __x)
 
  363       { _Base::insert(__position, __n, __x); }
 
  366 #if __cplusplus >= 201103L
 
  367       template<typename _InputIterator,
 
  368           typename = std::_RequireInputIter<_InputIterator>>
 
  370         insert(const_iterator __position,
 
  371           _InputIterator __first, _InputIterator __last)
 
  372         { return _Base::insert(__position, __first, __last); }
 
  374       template<typename _InputIterator>
 
  376         insert(iterator __position,
 
  377           _InputIterator __first, _InputIterator __last)
 
  378         { _Base::insert(__position, __first, __last); }
 
  382       pop_front() _GLIBCXX_NOEXCEPT
 
  388       pop_back() _GLIBCXX_NOEXCEPT
 
  394 #if __cplusplus >= 201103L
 
  395       erase(const_iterator __position)
 
  397       erase(iterator __position)   
 
  400    return _Base::erase(__position);
 
  404 #if __cplusplus >= 201103L
 
  405       erase(const_iterator __first, const_iterator __last)
 
  407       erase(iterator __first, iterator __last)
 
  410    // _GLIBCXX_RESOLVE_LIB_DEFECTS
 
  411    // 151. can't currently clear() empty container
 
  412         return _Base::erase(__first, __last);
 
  416       swap(deque& __x) _GLIBCXX_NOEXCEPT
 
  422       clear() _GLIBCXX_NOEXCEPT
 
  428       _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
 
  431       _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
 
  434   template<typename _Tp, typename _Alloc>
 
  436     operator==(const deque<_Tp, _Alloc>& __lhs,
 
  437           const deque<_Tp, _Alloc>& __rhs)
 
  438     { return __lhs._M_base() == __rhs._M_base(); }
 
  440   template<typename _Tp, typename _Alloc>
 
  442     operator!=(const deque<_Tp, _Alloc>& __lhs,
 
  443           const deque<_Tp, _Alloc>& __rhs)
 
  444     { return __lhs._M_base() != __rhs._M_base(); }
 
  446   template<typename _Tp, typename _Alloc>
 
  448     operator<(const deque<_Tp, _Alloc>& __lhs,
 
  449          const deque<_Tp, _Alloc>& __rhs)
 
  450     { return __lhs._M_base() < __rhs._M_base(); }
 
  452   template<typename _Tp, typename _Alloc>
 
  454     operator<=(const deque<_Tp, _Alloc>& __lhs,
 
  455           const deque<_Tp, _Alloc>& __rhs)
 
  456     { return __lhs._M_base() <= __rhs._M_base(); }
 
  458   template<typename _Tp, typename _Alloc>
 
  460     operator>=(const deque<_Tp, _Alloc>& __lhs,
 
  461           const deque<_Tp, _Alloc>& __rhs)
 
  462     { return __lhs._M_base() >= __rhs._M_base(); }
 
  464   template<typename _Tp, typename _Alloc>
 
  466     operator>(const deque<_Tp, _Alloc>& __lhs,
 
  467          const deque<_Tp, _Alloc>& __rhs)
 
  468     { return __lhs._M_base() > __rhs._M_base(); }
 
  470   template<typename _Tp, typename _Alloc>
 
  472     swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs)
 
  473     { __lhs.swap(__rhs); }
 
  475 } // namespace __profile