Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. // Debugging list implementation -*- C++ -*-
  2.  
  3. // Copyright (C) 2003-2015 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 debug/list
  26.  *  This file is a GNU debug extension to the Standard C++ Library.
  27.  */
  28.  
  29. #ifndef _GLIBCXX_DEBUG_LIST
  30. #define _GLIBCXX_DEBUG_LIST 1
  31.  
  32. #include <list>
  33. #include <debug/safe_sequence.h>
  34. #include <debug/safe_container.h>
  35. #include <debug/safe_iterator.h>
  36.  
  37. namespace std _GLIBCXX_VISIBILITY(default)
  38. {
  39. namespace __debug
  40. {
  41.   /// Class std::list with safety/checking/debug instrumentation.
  42.   template<typename _Tp, typename _Allocator = std::allocator<_Tp> >
  43.     class list
  44.     : public __gnu_debug::_Safe_container<
  45.         list<_Tp, _Allocator>, _Allocator,
  46.         __gnu_debug::_Safe_node_sequence, false>,
  47.       public _GLIBCXX_STD_C::list<_Tp, _Allocator>
  48.     {
  49.       typedef _GLIBCXX_STD_C::list<_Tp, _Allocator>                     _Base;
  50.       typedef __gnu_debug::_Safe_container<
  51.         list, _Allocator, __gnu_debug::_Safe_node_sequence, false>      _Safe;
  52.  
  53.       typedef typename _Base::iterator          _Base_iterator;
  54.       typedef typename _Base::const_iterator    _Base_const_iterator;
  55.       typedef __gnu_debug::_Equal_to<_Base_const_iterator>      _Equal;
  56.       typedef __gnu_debug::_Not_equal_to<_Base_const_iterator>  _Not_equal;
  57.  
  58.     public:
  59.       typedef typename _Base::reference                 reference;
  60.       typedef typename _Base::const_reference           const_reference;
  61.  
  62.       typedef __gnu_debug::_Safe_iterator<_Base_iterator, list>
  63.                                                         iterator;
  64.       typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, list>
  65.                                                         const_iterator;
  66.  
  67.       typedef typename _Base::size_type                 size_type;
  68.       typedef typename _Base::difference_type           difference_type;
  69.  
  70.       typedef _Tp                                       value_type;
  71.       typedef _Allocator                                allocator_type;
  72.       typedef typename _Base::pointer                   pointer;
  73.       typedef typename _Base::const_pointer             const_pointer;
  74.       typedef std::reverse_iterator<iterator>           reverse_iterator;
  75.       typedef std::reverse_iterator<const_iterator>     const_reverse_iterator;
  76.  
  77.       // 23.2.2.1 construct/copy/destroy:
  78.  
  79. #if __cplusplus < 201103L
  80.       list()
  81.       : _Base() { }
  82.  
  83.       list(const list& __x)
  84.       : _Base(__x) { }
  85.  
  86.       ~list() { }
  87. #else
  88.       list() = default;
  89.       list(const list&) = default;
  90.       list(list&&) = default;
  91.  
  92.       list(initializer_list<value_type> __l,
  93.            const allocator_type& __a = allocator_type())
  94.       : _Base(__l, __a) { }
  95.  
  96.       ~list() = default;
  97. #endif
  98.  
  99.       explicit
  100.       list(const _Allocator& __a) _GLIBCXX_NOEXCEPT
  101.       : _Base(__a) { }
  102.  
  103. #if __cplusplus >= 201103L
  104.       explicit
  105.       list(size_type __n)
  106.       : _Base(__n) { }
  107.  
  108.       list(size_type __n, const _Tp& __value,
  109.            const _Allocator& __a = _Allocator())
  110.       : _Base(__n, __value, __a) { }
  111. #else
  112.       explicit
  113.       list(size_type __n, const _Tp& __value = _Tp(),
  114.            const _Allocator& __a = _Allocator())
  115.       : _Base(__n, __value, __a) { }
  116. #endif
  117.  
  118. #if __cplusplus >= 201103L
  119.       template<class _InputIterator,
  120.                typename = std::_RequireInputIter<_InputIterator>>
  121. #else
  122.       template<class _InputIterator>
  123. #endif
  124.         list(_InputIterator __first, _InputIterator __last,
  125.              const _Allocator& __a = _Allocator())
  126.         : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
  127.                                                                      __last)),
  128.                 __gnu_debug::__base(__last), __a)
  129.         { }
  130.  
  131.       list(const _Base& __x)
  132.       : _Base(__x) { }
  133.  
  134. #if __cplusplus < 201103L
  135.       list&
  136.       operator=(const list& __x)
  137.       {
  138.         this->_M_safe() = __x;
  139.         _M_base() = __x;
  140.         return *this;
  141.       }
  142. #else
  143.       list&
  144.       operator=(const list&) = default;
  145.  
  146.       list&
  147.       operator=(list&&) = default;
  148.  
  149.       list&
  150.       operator=(initializer_list<value_type> __l)
  151.       {
  152.         this->_M_invalidate_all();
  153.         _M_base() = __l;
  154.         return *this;
  155.       }
  156.  
  157.       void
  158.       assign(initializer_list<value_type> __l)
  159.       {
  160.         _Base::assign(__l);
  161.         this->_M_invalidate_all();
  162.       }
  163. #endif
  164.  
  165. #if __cplusplus >= 201103L
  166.       template<class _InputIterator,
  167.                typename = std::_RequireInputIter<_InputIterator>>
  168. #else
  169.       template<class _InputIterator>
  170. #endif
  171.         void
  172.         assign(_InputIterator __first, _InputIterator __last)
  173.         {
  174.           __glibcxx_check_valid_range(__first, __last);
  175.           _Base::assign(__gnu_debug::__base(__first),
  176.                         __gnu_debug::__base(__last));
  177.           this->_M_invalidate_all();
  178.         }
  179.  
  180.       void
  181.       assign(size_type __n, const _Tp& __t)
  182.       {
  183.         _Base::assign(__n, __t);
  184.         this->_M_invalidate_all();
  185.       }
  186.  
  187.       using _Base::get_allocator;
  188.  
  189.       // iterators:
  190.       iterator
  191.       begin() _GLIBCXX_NOEXCEPT
  192.       { return iterator(_Base::begin(), this); }
  193.  
  194.       const_iterator
  195.       begin() const _GLIBCXX_NOEXCEPT
  196.       { return const_iterator(_Base::begin(), this); }
  197.  
  198.       iterator
  199.       end() _GLIBCXX_NOEXCEPT
  200.       { return iterator(_Base::end(), this); }
  201.  
  202.       const_iterator
  203.       end() const _GLIBCXX_NOEXCEPT
  204.       { return const_iterator(_Base::end(), this); }
  205.  
  206.       reverse_iterator
  207.       rbegin() _GLIBCXX_NOEXCEPT
  208.       { return reverse_iterator(end()); }
  209.  
  210.       const_reverse_iterator
  211.       rbegin() const _GLIBCXX_NOEXCEPT
  212.       { return const_reverse_iterator(end()); }
  213.  
  214.       reverse_iterator
  215.       rend() _GLIBCXX_NOEXCEPT
  216.       { return reverse_iterator(begin()); }
  217.  
  218.       const_reverse_iterator
  219.       rend() const _GLIBCXX_NOEXCEPT
  220.       { return const_reverse_iterator(begin()); }
  221.  
  222. #if __cplusplus >= 201103L
  223.       const_iterator
  224.       cbegin() const noexcept
  225.       { return const_iterator(_Base::begin(), this); }
  226.  
  227.       const_iterator
  228.       cend() const noexcept
  229.       { return const_iterator(_Base::end(), this); }
  230.  
  231.       const_reverse_iterator
  232.       crbegin() const noexcept
  233.       { return const_reverse_iterator(end()); }
  234.  
  235.       const_reverse_iterator
  236.       crend() const noexcept
  237.       { return const_reverse_iterator(begin()); }
  238. #endif
  239.  
  240.       // 23.2.2.2 capacity:
  241.       using _Base::empty;
  242.       using _Base::size;
  243.       using _Base::max_size;
  244.  
  245. #if __cplusplus >= 201103L
  246.       void
  247.       resize(size_type __sz)
  248.       {
  249.         this->_M_detach_singular();
  250.  
  251.         // if __sz < size(), invalidate all iterators in [begin + __sz, end())
  252.         _Base_iterator __victim = _Base::begin();
  253.         _Base_iterator __end = _Base::end();
  254.         for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
  255.           ++__victim;
  256.  
  257.         for (; __victim != __end; ++__victim)
  258.           this->_M_invalidate_if(_Equal(__victim));
  259.  
  260.         __try
  261.           {
  262.             _Base::resize(__sz);
  263.           }
  264.         __catch(...)
  265.           {
  266.             this->_M_revalidate_singular();
  267.             __throw_exception_again;
  268.           }
  269.       }
  270.  
  271.       void
  272.       resize(size_type __sz, const _Tp& __c)
  273.       {
  274.         this->_M_detach_singular();
  275.  
  276.         // if __sz < size(), invalidate all iterators in [begin + __sz, end())
  277.         _Base_iterator __victim = _Base::begin();
  278.         _Base_iterator __end = _Base::end();
  279.         for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
  280.           ++__victim;
  281.  
  282.         for (; __victim != __end; ++__victim)
  283.           this->_M_invalidate_if(_Equal(__victim));
  284.  
  285.         __try
  286.           {
  287.             _Base::resize(__sz, __c);
  288.           }
  289.         __catch(...)
  290.           {
  291.             this->_M_revalidate_singular();
  292.             __throw_exception_again;
  293.           }
  294.       }
  295. #else
  296.       void
  297.       resize(size_type __sz, _Tp __c = _Tp())
  298.       {
  299.         this->_M_detach_singular();
  300.  
  301.         // if __sz < size(), invalidate all iterators in [begin + __sz, end())
  302.         _Base_iterator __victim = _Base::begin();
  303.         _Base_iterator __end = _Base::end();
  304.         for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
  305.           ++__victim;
  306.  
  307.         for (; __victim != __end; ++__victim)
  308.           this->_M_invalidate_if(_Equal(__victim));
  309.  
  310.         __try
  311.           {
  312.             _Base::resize(__sz, __c);
  313.           }
  314.         __catch(...)
  315.           {
  316.             this->_M_revalidate_singular();
  317.             __throw_exception_again;
  318.           }
  319.       }
  320. #endif
  321.  
  322.       // element access:
  323.       reference
  324.       front() _GLIBCXX_NOEXCEPT
  325.       {
  326.         __glibcxx_check_nonempty();
  327.         return _Base::front();
  328.       }
  329.  
  330.       const_reference
  331.       front() const _GLIBCXX_NOEXCEPT
  332.       {
  333.         __glibcxx_check_nonempty();
  334.         return _Base::front();
  335.       }
  336.  
  337.       reference
  338.       back() _GLIBCXX_NOEXCEPT
  339.       {
  340.         __glibcxx_check_nonempty();
  341.         return _Base::back();
  342.       }
  343.  
  344.       const_reference
  345.       back() const _GLIBCXX_NOEXCEPT
  346.       {
  347.         __glibcxx_check_nonempty();
  348.         return _Base::back();
  349.       }
  350.  
  351.       // 23.2.2.3 modifiers:
  352.       using _Base::push_front;
  353.  
  354. #if __cplusplus >= 201103L
  355.       using _Base::emplace_front;
  356. #endif
  357.  
  358.       void
  359.       pop_front() _GLIBCXX_NOEXCEPT
  360.       {
  361.         __glibcxx_check_nonempty();
  362.         this->_M_invalidate_if(_Equal(_Base::begin()));
  363.         _Base::pop_front();
  364.       }
  365.  
  366.       using _Base::push_back;
  367.  
  368. #if __cplusplus >= 201103L
  369.       using _Base::emplace_back;
  370. #endif
  371.  
  372.       void
  373.       pop_back() _GLIBCXX_NOEXCEPT
  374.       {
  375.         __glibcxx_check_nonempty();
  376.         this->_M_invalidate_if(_Equal(--_Base::end()));
  377.         _Base::pop_back();
  378.       }
  379.  
  380. #if __cplusplus >= 201103L
  381.       template<typename... _Args>
  382.         iterator
  383.         emplace(const_iterator __position, _Args&&... __args)
  384.         {
  385.           __glibcxx_check_insert(__position);
  386.           return iterator(_Base::emplace(__position.base(),
  387.                                         std::forward<_Args>(__args)...), this);
  388.         }
  389. #endif
  390.  
  391.      iterator
  392. #if __cplusplus >= 201103L
  393.      insert(const_iterator __position, const _Tp& __x)
  394. #else
  395.      insert(iterator __position, const _Tp& __x)
  396. #endif
  397.      {
  398.        __glibcxx_check_insert(__position);
  399.        return iterator(_Base::insert(__position.base(), __x), this);
  400.      }
  401.  
  402. #if __cplusplus >= 201103L
  403.       iterator
  404.       insert(const_iterator __position, _Tp&& __x)
  405.       { return emplace(__position, std::move(__x)); }
  406.  
  407.       iterator
  408.       insert(const_iterator __p, initializer_list<value_type> __l)
  409.       {
  410.         __glibcxx_check_insert(__p);
  411.         return iterator(_Base::insert(__p.base(), __l), this);
  412.       }
  413. #endif
  414.  
  415. #if __cplusplus >= 201103L
  416.       iterator
  417.       insert(const_iterator __position, size_type __n, const _Tp& __x)
  418.       {
  419.         __glibcxx_check_insert(__position);
  420.         return iterator(_Base::insert(__position.base(), __n, __x), this);
  421.       }
  422. #else
  423.       void
  424.       insert(iterator __position, size_type __n, const _Tp& __x)
  425.       {
  426.         __glibcxx_check_insert(__position);
  427.         _Base::insert(__position.base(), __n, __x);
  428.       }
  429. #endif
  430.  
  431. #if __cplusplus >= 201103L
  432.       template<class _InputIterator,
  433.                typename = std::_RequireInputIter<_InputIterator>>
  434.         iterator
  435.         insert(const_iterator __position, _InputIterator __first,
  436.                _InputIterator __last)
  437.         {
  438.           __glibcxx_check_insert_range(__position, __first, __last);
  439.           return iterator(_Base::insert(__position.base(),
  440.                                         __gnu_debug::__base(__first),
  441.                                         __gnu_debug::__base(__last)),
  442.                           this);
  443.         }
  444. #else
  445.       template<class _InputIterator>
  446.         void
  447.         insert(iterator __position, _InputIterator __first,
  448.                _InputIterator __last)
  449.         {
  450.           __glibcxx_check_insert_range(__position, __first, __last);
  451.           _Base::insert(__position.base(), __gnu_debug::__base(__first),
  452.                                            __gnu_debug::__base(__last));
  453.         }
  454. #endif
  455.  
  456.     private:
  457.       _Base_iterator
  458. #if __cplusplus >= 201103L
  459.       _M_erase(_Base_const_iterator __position) noexcept
  460. #else
  461.       _M_erase(_Base_iterator __position)
  462. #endif
  463.       {
  464.         this->_M_invalidate_if(_Equal(__position));
  465.         return _Base::erase(__position);
  466.       }
  467.  
  468.     public:
  469.       iterator
  470. #if __cplusplus >= 201103L
  471.       erase(const_iterator __position) noexcept
  472. #else
  473.       erase(iterator __position)
  474. #endif
  475.       {
  476.         __glibcxx_check_erase(__position);
  477.         return iterator(_M_erase(__position.base()), this);
  478.       }
  479.  
  480.       iterator
  481. #if __cplusplus >= 201103L
  482.       erase(const_iterator __first, const_iterator __last) noexcept
  483. #else
  484.       erase(iterator __first, iterator __last)
  485. #endif
  486.       {
  487.         // _GLIBCXX_RESOLVE_LIB_DEFECTS
  488.         // 151. can't currently clear() empty container
  489.         __glibcxx_check_erase_range(__first, __last);
  490.         for (_Base_const_iterator __victim = __first.base();
  491.              __victim != __last.base(); ++__victim)
  492.           {
  493.             _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
  494.                                   _M_message(__gnu_debug::__msg_valid_range)
  495.                                   ._M_iterator(__first, "position")
  496.                                   ._M_iterator(__last, "last"));
  497.             this->_M_invalidate_if(_Equal(__victim));
  498.           }
  499.         return iterator(_Base::erase(__first.base(), __last.base()), this);
  500.       }
  501.  
  502.       void
  503.       swap(list& __x)
  504. #if __cplusplus >= 201103L
  505.         noexcept( noexcept(declval<_Base>().swap(__x)) )
  506. #endif
  507.       {
  508.         _Safe::_M_swap(__x);
  509.         _Base::swap(__x);
  510.       }
  511.  
  512.       void
  513.       clear() _GLIBCXX_NOEXCEPT
  514.       {
  515.         _Base::clear();
  516.         this->_M_invalidate_all();
  517.       }
  518.  
  519.       // 23.2.2.4 list operations:
  520.       void
  521. #if __cplusplus >= 201103L
  522.       splice(const_iterator __position, list&& __x) noexcept
  523. #else
  524.       splice(iterator __position, list& __x)
  525. #endif
  526.       {
  527.         _GLIBCXX_DEBUG_VERIFY(&__x != this,
  528.                               _M_message(__gnu_debug::__msg_self_splice)
  529.                               ._M_sequence(*this, "this"));
  530.         this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
  531.         _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()));
  532.       }
  533.  
  534. #if __cplusplus >= 201103L
  535.       void
  536.       splice(const_iterator __position, list& __x) noexcept
  537.       { splice(__position, std::move(__x)); }
  538. #endif
  539.  
  540.       void
  541. #if __cplusplus >= 201103L
  542.       splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
  543. #else
  544.       splice(iterator __position, list& __x, iterator __i)
  545. #endif
  546.       {
  547.         __glibcxx_check_insert(__position);
  548.  
  549.         // We used to perform the splice_alloc check:  not anymore, redundant
  550.         // after implementing the relevant bits of N1599.
  551.  
  552.         _GLIBCXX_DEBUG_VERIFY(__i._M_dereferenceable(),
  553.                               _M_message(__gnu_debug::__msg_splice_bad)
  554.                               ._M_iterator(__i, "__i"));
  555.         _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__x),
  556.                               _M_message(__gnu_debug::__msg_splice_other)
  557.                              ._M_iterator(__i, "__i")._M_sequence(__x, "__x"));
  558.  
  559.         // _GLIBCXX_RESOLVE_LIB_DEFECTS
  560.         // 250. splicing invalidates iterators
  561.         this->_M_transfer_from_if(__x, _Equal(__i.base()));
  562.         _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
  563.                       __i.base());
  564.       }
  565.  
  566. #if __cplusplus >= 201103L
  567.       void
  568.       splice(const_iterator __position, list& __x, const_iterator __i) noexcept
  569.       { splice(__position, std::move(__x), __i); }
  570. #endif
  571.  
  572.       void
  573. #if __cplusplus >= 201103L
  574.       splice(const_iterator __position, list&& __x, const_iterator __first,
  575.              const_iterator __last) noexcept
  576. #else
  577.       splice(iterator __position, list& __x, iterator __first,
  578.              iterator __last)
  579. #endif
  580.       {
  581.         __glibcxx_check_insert(__position);
  582.         __glibcxx_check_valid_range(__first, __last);
  583.         _GLIBCXX_DEBUG_VERIFY(__first._M_attached_to(&__x),
  584.                               _M_message(__gnu_debug::__msg_splice_other)
  585.                               ._M_sequence(__x, "x")
  586.                               ._M_iterator(__first, "first"));
  587.  
  588.         // We used to perform the splice_alloc check:  not anymore, redundant
  589.         // after implementing the relevant bits of N1599.
  590.  
  591.         for (_Base_const_iterator __tmp = __first.base();
  592.              __tmp != __last.base(); ++__tmp)
  593.           {
  594.             _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
  595.                                   _M_message(__gnu_debug::__msg_valid_range)
  596.                                   ._M_iterator(__first, "first")
  597.                                   ._M_iterator(__last, "last"));
  598.             _GLIBCXX_DEBUG_VERIFY(&__x != this || __tmp != __position.base(),
  599.                                 _M_message(__gnu_debug::__msg_splice_overlap)
  600.                                   ._M_iterator(__tmp, "position")
  601.                                   ._M_iterator(__first, "first")
  602.                                   ._M_iterator(__last, "last"));
  603.             // _GLIBCXX_RESOLVE_LIB_DEFECTS
  604.             // 250. splicing invalidates iterators
  605.             this->_M_transfer_from_if(__x, _Equal(__tmp));
  606.           }
  607.  
  608.         _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()),
  609.                       __first.base(), __last.base());
  610.       }
  611.  
  612. #if __cplusplus >= 201103L
  613.       void
  614.       splice(const_iterator __position, list& __x,
  615.              const_iterator __first, const_iterator __last) noexcept
  616.       { splice(__position, std::move(__x), __first, __last); }
  617. #endif
  618.  
  619.       void
  620.       remove(const _Tp& __value)
  621.       {
  622.         for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
  623.           {
  624.             if (*__x == __value)
  625.               __x = _M_erase(__x);
  626.             else
  627.               ++__x;
  628.           }
  629.       }
  630.  
  631.       template<class _Predicate>
  632.         void
  633.         remove_if(_Predicate __pred)
  634.         {
  635.           for (_Base_iterator __x = _Base::begin(); __x != _Base::end(); )
  636.             {
  637.               if (__pred(*__x))
  638.                 __x = _M_erase(__x);
  639.               else
  640.                 ++__x;
  641.             }
  642.         }
  643.  
  644.       void
  645.       unique()
  646.       {
  647.         _Base_iterator __first = _Base::begin();
  648.         _Base_iterator __last = _Base::end();
  649.         if (__first == __last)
  650.           return;
  651.         _Base_iterator __next = __first; ++__next;
  652.         while (__next != __last)
  653.           {
  654.             if (*__first == *__next)
  655.               __next = _M_erase(__next);
  656.             else
  657.               __first = __next++;
  658.           }
  659.       }
  660.  
  661.       template<class _BinaryPredicate>
  662.         void
  663.         unique(_BinaryPredicate __binary_pred)
  664.         {
  665.           _Base_iterator __first = _Base::begin();
  666.           _Base_iterator __last = _Base::end();
  667.           if (__first == __last)
  668.             return;
  669.           _Base_iterator __next = __first; ++__next;
  670.           while (__next != __last)
  671.             {
  672.               if (__binary_pred(*__first, *__next))
  673.                 __next = _M_erase(__next);
  674.               else
  675.                 __first = __next++;
  676.             }
  677.         }
  678.  
  679.       void
  680. #if __cplusplus >= 201103L
  681.       merge(list&& __x)
  682. #else
  683.       merge(list& __x)
  684. #endif
  685.       {
  686.         // _GLIBCXX_RESOLVE_LIB_DEFECTS
  687.         // 300. list::merge() specification incomplete
  688.         if (this != &__x)
  689.           {
  690.             __glibcxx_check_sorted(_Base::begin(), _Base::end());
  691.             __glibcxx_check_sorted(__x.begin().base(), __x.end().base());
  692.             this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
  693.             _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
  694.           }
  695.       }
  696.  
  697. #if __cplusplus >= 201103L
  698.       void
  699.       merge(list& __x)
  700.       { merge(std::move(__x)); }
  701. #endif
  702.  
  703.       template<class _Compare>
  704.         void
  705. #if __cplusplus >= 201103L
  706.         merge(list&& __x, _Compare __comp)
  707. #else
  708.         merge(list& __x, _Compare __comp)
  709. #endif
  710.         {
  711.           // _GLIBCXX_RESOLVE_LIB_DEFECTS
  712.           // 300. list::merge() specification incomplete
  713.           if (this != &__x)
  714.             {
  715.               __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(),
  716.                                           __comp);
  717.               __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(),
  718.                                           __comp);
  719.               this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
  720.               _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
  721.             }
  722.         }
  723.  
  724. #if __cplusplus >= 201103L
  725.       template<typename _Compare>
  726.         void
  727.         merge(list& __x, _Compare __comp)
  728.         { merge(std::move(__x), __comp); }
  729. #endif
  730.  
  731.       void
  732.       sort() { _Base::sort(); }
  733.  
  734.       template<typename _StrictWeakOrdering>
  735.         void
  736.         sort(_StrictWeakOrdering __pred) { _Base::sort(__pred); }
  737.  
  738.       using _Base::reverse;
  739.  
  740.       _Base&
  741.       _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
  742.  
  743.       const _Base&
  744.       _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
  745.     };
  746.  
  747.   template<typename _Tp, typename _Alloc>
  748.     inline bool
  749.     operator==(const list<_Tp, _Alloc>& __lhs,
  750.                const list<_Tp, _Alloc>& __rhs)
  751.     { return __lhs._M_base() == __rhs._M_base(); }
  752.  
  753.   template<typename _Tp, typename _Alloc>
  754.     inline bool
  755.     operator!=(const list<_Tp, _Alloc>& __lhs,
  756.                const list<_Tp, _Alloc>& __rhs)
  757.     { return __lhs._M_base() != __rhs._M_base(); }
  758.  
  759.   template<typename _Tp, typename _Alloc>
  760.     inline bool
  761.     operator<(const list<_Tp, _Alloc>& __lhs,
  762.               const list<_Tp, _Alloc>& __rhs)
  763.     { return __lhs._M_base() < __rhs._M_base(); }
  764.  
  765.   template<typename _Tp, typename _Alloc>
  766.     inline bool
  767.     operator<=(const list<_Tp, _Alloc>& __lhs,
  768.                const list<_Tp, _Alloc>& __rhs)
  769.     { return __lhs._M_base() <= __rhs._M_base(); }
  770.  
  771.   template<typename _Tp, typename _Alloc>
  772.     inline bool
  773.     operator>=(const list<_Tp, _Alloc>& __lhs,
  774.                const list<_Tp, _Alloc>& __rhs)
  775.     { return __lhs._M_base() >= __rhs._M_base(); }
  776.  
  777.   template<typename _Tp, typename _Alloc>
  778.     inline bool
  779.     operator>(const list<_Tp, _Alloc>& __lhs,
  780.               const list<_Tp, _Alloc>& __rhs)
  781.     { return __lhs._M_base() > __rhs._M_base(); }
  782.  
  783.   template<typename _Tp, typename _Alloc>
  784.     inline void
  785.     swap(list<_Tp, _Alloc>& __lhs, list<_Tp, _Alloc>& __rhs)
  786.     { __lhs.swap(__rhs); }
  787.  
  788. } // namespace __debug
  789. } // namespace std
  790.  
  791. #ifndef _GLIBCXX_DEBUG_PEDANTIC
  792. namespace __gnu_debug
  793. {
  794.   template<class _Tp, class _Alloc>
  795.     struct _Insert_range_from_self_is_safe<std::__debug::list<_Tp, _Alloc> >
  796.     { enum { __value = 1 }; };
  797. }
  798. #endif
  799.  
  800. #endif
  801.