xref: /dflybsd-src/contrib/gcc-8.0/libstdc++-v3/include/bits/stl_list.h (revision 95059079af47f9a66a175f374f2da1a5020e3255)
138fd1498Szrj // List implementation -*- C++ -*-
238fd1498Szrj 
338fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc.
438fd1498Szrj //
538fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
638fd1498Szrj // software; you can redistribute it and/or modify it under the
738fd1498Szrj // terms of the GNU General Public License as published by the
838fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
938fd1498Szrj // any later version.
1038fd1498Szrj 
1138fd1498Szrj // This library is distributed in the hope that it will be useful,
1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1438fd1498Szrj // GNU General Public License for more details.
1538fd1498Szrj 
1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
1838fd1498Szrj // 3.1, as published by the Free Software Foundation.
1938fd1498Szrj 
2038fd1498Szrj // You should have received a copy of the GNU General Public License and
2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2338fd1498Szrj // <http://www.gnu.org/licenses/>.
2438fd1498Szrj 
2538fd1498Szrj /*
2638fd1498Szrj  *
2738fd1498Szrj  * Copyright (c) 1994
2838fd1498Szrj  * Hewlett-Packard Company
2938fd1498Szrj  *
3038fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
3138fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
3238fd1498Szrj  * provided that the above copyright notice appear in all copies and
3338fd1498Szrj  * that both that copyright notice and this permission notice appear
3438fd1498Szrj  * in supporting documentation.  Hewlett-Packard Company makes no
3538fd1498Szrj  * representations about the suitability of this software for any
3638fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
3738fd1498Szrj  *
3838fd1498Szrj  *
3938fd1498Szrj  * Copyright (c) 1996,1997
4038fd1498Szrj  * Silicon Graphics Computer Systems, Inc.
4138fd1498Szrj  *
4238fd1498Szrj  * Permission to use, copy, modify, distribute and sell this software
4338fd1498Szrj  * and its documentation for any purpose is hereby granted without fee,
4438fd1498Szrj  * provided that the above copyright notice appear in all copies and
4538fd1498Szrj  * that both that copyright notice and this permission notice appear
4638fd1498Szrj  * in supporting documentation.  Silicon Graphics makes no
4738fd1498Szrj  * representations about the suitability of this software for any
4838fd1498Szrj  * purpose.  It is provided "as is" without express or implied warranty.
4938fd1498Szrj  */
5038fd1498Szrj 
5138fd1498Szrj /** @file bits/stl_list.h
5238fd1498Szrj  *  This is an internal header file, included by other library headers.
5338fd1498Szrj  *  Do not attempt to use it directly. @headername{list}
5438fd1498Szrj  */
5538fd1498Szrj 
5638fd1498Szrj #ifndef _STL_LIST_H
5738fd1498Szrj #define _STL_LIST_H 1
5838fd1498Szrj 
5938fd1498Szrj #include <bits/concept_check.h>
6038fd1498Szrj #include <ext/alloc_traits.h>
6138fd1498Szrj #if __cplusplus >= 201103L
6238fd1498Szrj #include <initializer_list>
6338fd1498Szrj #include <bits/allocated_ptr.h>
6438fd1498Szrj #include <ext/aligned_buffer.h>
6538fd1498Szrj #endif
6638fd1498Szrj 
_GLIBCXX_VISIBILITY(default)6738fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
6838fd1498Szrj {
6938fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
7038fd1498Szrj 
7138fd1498Szrj   namespace __detail
7238fd1498Szrj   {
7338fd1498Szrj     // Supporting structures are split into common and templated
7438fd1498Szrj     // types; the latter publicly inherits from the former in an
7538fd1498Szrj     // effort to reduce code duplication.  This results in some
7638fd1498Szrj     // "needless" static_cast'ing later on, but it's all safe
7738fd1498Szrj     // downcasting.
7838fd1498Szrj 
7938fd1498Szrj     /// Common part of a node in the %list.
8038fd1498Szrj     struct _List_node_base
8138fd1498Szrj     {
8238fd1498Szrj       _List_node_base* _M_next;
8338fd1498Szrj       _List_node_base* _M_prev;
8438fd1498Szrj 
8538fd1498Szrj       static void
8638fd1498Szrj       swap(_List_node_base& __x, _List_node_base& __y) _GLIBCXX_USE_NOEXCEPT;
8738fd1498Szrj 
8838fd1498Szrj       void
8938fd1498Szrj       _M_transfer(_List_node_base* const __first,
9038fd1498Szrj 		  _List_node_base* const __last) _GLIBCXX_USE_NOEXCEPT;
9138fd1498Szrj 
9238fd1498Szrj       void
9338fd1498Szrj       _M_reverse() _GLIBCXX_USE_NOEXCEPT;
9438fd1498Szrj 
9538fd1498Szrj       void
9638fd1498Szrj       _M_hook(_List_node_base* const __position) _GLIBCXX_USE_NOEXCEPT;
9738fd1498Szrj 
9838fd1498Szrj       void
9938fd1498Szrj       _M_unhook() _GLIBCXX_USE_NOEXCEPT;
10038fd1498Szrj     };
10138fd1498Szrj 
10238fd1498Szrj     /// The %list node header.
10338fd1498Szrj     struct _List_node_header : public _List_node_base
10438fd1498Szrj     {
10538fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
10638fd1498Szrj       std::size_t _M_size;
10738fd1498Szrj #endif
10838fd1498Szrj 
10938fd1498Szrj       _List_node_header() _GLIBCXX_NOEXCEPT
11038fd1498Szrj       { _M_init(); }
11138fd1498Szrj 
11238fd1498Szrj #if __cplusplus >= 201103L
11338fd1498Szrj       _List_node_header(_List_node_header&& __x) noexcept
11438fd1498Szrj       : _List_node_base{ __x._M_next, __x._M_prev }
11538fd1498Szrj # if _GLIBCXX_USE_CXX11_ABI
11638fd1498Szrj       , _M_size(__x._M_size)
11738fd1498Szrj # endif
11838fd1498Szrj       {
11938fd1498Szrj 	if (__x._M_base()->_M_next == __x._M_base())
12038fd1498Szrj 	  this->_M_next = this->_M_prev = this;
12138fd1498Szrj 	else
12238fd1498Szrj 	  {
12338fd1498Szrj 	    this->_M_next->_M_prev = this->_M_prev->_M_next = this->_M_base();
12438fd1498Szrj 	    __x._M_init();
12538fd1498Szrj 	  }
12638fd1498Szrj       }
12738fd1498Szrj 
12838fd1498Szrj       void
12938fd1498Szrj       _M_move_nodes(_List_node_header&& __x)
13038fd1498Szrj       {
13138fd1498Szrj 	_List_node_base* const __xnode = __x._M_base();
13238fd1498Szrj 	if (__xnode->_M_next == __xnode)
13338fd1498Szrj 	  _M_init();
13438fd1498Szrj 	else
13538fd1498Szrj 	  {
13638fd1498Szrj 	    _List_node_base* const __node = this->_M_base();
13738fd1498Szrj 	    __node->_M_next = __xnode->_M_next;
13838fd1498Szrj 	    __node->_M_prev = __xnode->_M_prev;
13938fd1498Szrj 	    __node->_M_next->_M_prev = __node->_M_prev->_M_next = __node;
14038fd1498Szrj # if _GLIBCXX_USE_CXX11_ABI
14138fd1498Szrj 	    _M_size = __x._M_size;
14238fd1498Szrj # endif
14338fd1498Szrj 	    __x._M_init();
14438fd1498Szrj 	  }
14538fd1498Szrj       }
14638fd1498Szrj #endif
14738fd1498Szrj 
14838fd1498Szrj       void
14938fd1498Szrj       _M_init() _GLIBCXX_NOEXCEPT
15038fd1498Szrj       {
15138fd1498Szrj 	this->_M_next = this->_M_prev = this;
15238fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
15338fd1498Szrj 	this->_M_size = 0;
15438fd1498Szrj #endif
15538fd1498Szrj       }
15638fd1498Szrj 
15738fd1498Szrj     private:
15838fd1498Szrj       _List_node_base* _M_base() { return this; }
15938fd1498Szrj     };
16038fd1498Szrj   } // namespace detail
16138fd1498Szrj 
16238fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
16338fd1498Szrj 
16438fd1498Szrj   /// An actual node in the %list.
16538fd1498Szrj   template<typename _Tp>
16638fd1498Szrj     struct _List_node : public __detail::_List_node_base
16738fd1498Szrj     {
16838fd1498Szrj #if __cplusplus >= 201103L
16938fd1498Szrj       __gnu_cxx::__aligned_membuf<_Tp> _M_storage;
17038fd1498Szrj       _Tp*       _M_valptr()       { return _M_storage._M_ptr(); }
17138fd1498Szrj       _Tp const* _M_valptr() const { return _M_storage._M_ptr(); }
17238fd1498Szrj #else
17338fd1498Szrj       _Tp _M_data;
17438fd1498Szrj       _Tp*       _M_valptr()       { return std::__addressof(_M_data); }
17538fd1498Szrj       _Tp const* _M_valptr() const { return std::__addressof(_M_data); }
17638fd1498Szrj #endif
17738fd1498Szrj     };
17838fd1498Szrj 
17938fd1498Szrj   /**
18038fd1498Szrj    *  @brief A list::iterator.
18138fd1498Szrj    *
18238fd1498Szrj    *  All the functions are op overloads.
18338fd1498Szrj   */
18438fd1498Szrj   template<typename _Tp>
18538fd1498Szrj     struct _List_iterator
18638fd1498Szrj     {
18738fd1498Szrj       typedef _List_iterator<_Tp>		_Self;
18838fd1498Szrj       typedef _List_node<_Tp>			_Node;
18938fd1498Szrj 
19038fd1498Szrj       typedef ptrdiff_t				difference_type;
19138fd1498Szrj       typedef std::bidirectional_iterator_tag	iterator_category;
19238fd1498Szrj       typedef _Tp				value_type;
19338fd1498Szrj       typedef _Tp*				pointer;
19438fd1498Szrj       typedef _Tp&				reference;
19538fd1498Szrj 
19638fd1498Szrj       _List_iterator() _GLIBCXX_NOEXCEPT
19738fd1498Szrj       : _M_node() { }
19838fd1498Szrj 
19938fd1498Szrj       explicit
20038fd1498Szrj       _List_iterator(__detail::_List_node_base* __x) _GLIBCXX_NOEXCEPT
20138fd1498Szrj       : _M_node(__x) { }
20238fd1498Szrj 
20338fd1498Szrj       _Self
20438fd1498Szrj       _M_const_cast() const _GLIBCXX_NOEXCEPT
20538fd1498Szrj       { return *this; }
20638fd1498Szrj 
20738fd1498Szrj       // Must downcast from _List_node_base to _List_node to get to value.
20838fd1498Szrj       reference
20938fd1498Szrj       operator*() const _GLIBCXX_NOEXCEPT
21038fd1498Szrj       { return *static_cast<_Node*>(_M_node)->_M_valptr(); }
21138fd1498Szrj 
21238fd1498Szrj       pointer
21338fd1498Szrj       operator->() const _GLIBCXX_NOEXCEPT
21438fd1498Szrj       { return static_cast<_Node*>(_M_node)->_M_valptr(); }
21538fd1498Szrj 
21638fd1498Szrj       _Self&
21738fd1498Szrj       operator++() _GLIBCXX_NOEXCEPT
21838fd1498Szrj       {
21938fd1498Szrj 	_M_node = _M_node->_M_next;
22038fd1498Szrj 	return *this;
22138fd1498Szrj       }
22238fd1498Szrj 
22338fd1498Szrj       _Self
22438fd1498Szrj       operator++(int) _GLIBCXX_NOEXCEPT
22538fd1498Szrj       {
22638fd1498Szrj 	_Self __tmp = *this;
22738fd1498Szrj 	_M_node = _M_node->_M_next;
22838fd1498Szrj 	return __tmp;
22938fd1498Szrj       }
23038fd1498Szrj 
23138fd1498Szrj       _Self&
23238fd1498Szrj       operator--() _GLIBCXX_NOEXCEPT
23338fd1498Szrj       {
23438fd1498Szrj 	_M_node = _M_node->_M_prev;
23538fd1498Szrj 	return *this;
23638fd1498Szrj       }
23738fd1498Szrj 
23838fd1498Szrj       _Self
23938fd1498Szrj       operator--(int) _GLIBCXX_NOEXCEPT
24038fd1498Szrj       {
24138fd1498Szrj 	_Self __tmp = *this;
24238fd1498Szrj 	_M_node = _M_node->_M_prev;
24338fd1498Szrj 	return __tmp;
24438fd1498Szrj       }
24538fd1498Szrj 
24638fd1498Szrj       bool
24738fd1498Szrj       operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
24838fd1498Szrj       { return _M_node == __x._M_node; }
24938fd1498Szrj 
25038fd1498Szrj       bool
25138fd1498Szrj       operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
25238fd1498Szrj       { return _M_node != __x._M_node; }
25338fd1498Szrj 
25438fd1498Szrj       // The only member points to the %list element.
25538fd1498Szrj       __detail::_List_node_base* _M_node;
25638fd1498Szrj     };
25738fd1498Szrj 
25838fd1498Szrj   /**
25938fd1498Szrj    *  @brief A list::const_iterator.
26038fd1498Szrj    *
26138fd1498Szrj    *  All the functions are op overloads.
26238fd1498Szrj   */
26338fd1498Szrj   template<typename _Tp>
26438fd1498Szrj     struct _List_const_iterator
26538fd1498Szrj     {
26638fd1498Szrj       typedef _List_const_iterator<_Tp>		_Self;
26738fd1498Szrj       typedef const _List_node<_Tp>		_Node;
26838fd1498Szrj       typedef _List_iterator<_Tp>		iterator;
26938fd1498Szrj 
27038fd1498Szrj       typedef ptrdiff_t				difference_type;
27138fd1498Szrj       typedef std::bidirectional_iterator_tag	iterator_category;
27238fd1498Szrj       typedef _Tp				value_type;
27338fd1498Szrj       typedef const _Tp*			pointer;
27438fd1498Szrj       typedef const _Tp&			reference;
27538fd1498Szrj 
27638fd1498Szrj       _List_const_iterator() _GLIBCXX_NOEXCEPT
27738fd1498Szrj       : _M_node() { }
27838fd1498Szrj 
27938fd1498Szrj       explicit
28038fd1498Szrj       _List_const_iterator(const __detail::_List_node_base* __x)
28138fd1498Szrj       _GLIBCXX_NOEXCEPT
28238fd1498Szrj       : _M_node(__x) { }
28338fd1498Szrj 
28438fd1498Szrj       _List_const_iterator(const iterator& __x) _GLIBCXX_NOEXCEPT
28538fd1498Szrj       : _M_node(__x._M_node) { }
28638fd1498Szrj 
28738fd1498Szrj       iterator
28838fd1498Szrj       _M_const_cast() const _GLIBCXX_NOEXCEPT
28938fd1498Szrj       { return iterator(const_cast<__detail::_List_node_base*>(_M_node)); }
29038fd1498Szrj 
29138fd1498Szrj       // Must downcast from List_node_base to _List_node to get to value.
29238fd1498Szrj       reference
29338fd1498Szrj       operator*() const _GLIBCXX_NOEXCEPT
29438fd1498Szrj       { return *static_cast<_Node*>(_M_node)->_M_valptr(); }
29538fd1498Szrj 
29638fd1498Szrj       pointer
29738fd1498Szrj       operator->() const _GLIBCXX_NOEXCEPT
29838fd1498Szrj       { return static_cast<_Node*>(_M_node)->_M_valptr(); }
29938fd1498Szrj 
30038fd1498Szrj       _Self&
30138fd1498Szrj       operator++() _GLIBCXX_NOEXCEPT
30238fd1498Szrj       {
30338fd1498Szrj 	_M_node = _M_node->_M_next;
30438fd1498Szrj 	return *this;
30538fd1498Szrj       }
30638fd1498Szrj 
30738fd1498Szrj       _Self
30838fd1498Szrj       operator++(int) _GLIBCXX_NOEXCEPT
30938fd1498Szrj       {
31038fd1498Szrj 	_Self __tmp = *this;
31138fd1498Szrj 	_M_node = _M_node->_M_next;
31238fd1498Szrj 	return __tmp;
31338fd1498Szrj       }
31438fd1498Szrj 
31538fd1498Szrj       _Self&
31638fd1498Szrj       operator--() _GLIBCXX_NOEXCEPT
31738fd1498Szrj       {
31838fd1498Szrj 	_M_node = _M_node->_M_prev;
31938fd1498Szrj 	return *this;
32038fd1498Szrj       }
32138fd1498Szrj 
32238fd1498Szrj       _Self
32338fd1498Szrj       operator--(int) _GLIBCXX_NOEXCEPT
32438fd1498Szrj       {
32538fd1498Szrj 	_Self __tmp = *this;
32638fd1498Szrj 	_M_node = _M_node->_M_prev;
32738fd1498Szrj 	return __tmp;
32838fd1498Szrj       }
32938fd1498Szrj 
33038fd1498Szrj       bool
33138fd1498Szrj       operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
33238fd1498Szrj       { return _M_node == __x._M_node; }
33338fd1498Szrj 
33438fd1498Szrj       bool
33538fd1498Szrj       operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
33638fd1498Szrj       { return _M_node != __x._M_node; }
33738fd1498Szrj 
33838fd1498Szrj       // The only member points to the %list element.
33938fd1498Szrj       const __detail::_List_node_base* _M_node;
34038fd1498Szrj     };
34138fd1498Szrj 
34238fd1498Szrj   template<typename _Val>
34338fd1498Szrj     inline bool
34438fd1498Szrj     operator==(const _List_iterator<_Val>& __x,
34538fd1498Szrj 	       const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
34638fd1498Szrj     { return __x._M_node == __y._M_node; }
34738fd1498Szrj 
34838fd1498Szrj   template<typename _Val>
34938fd1498Szrj     inline bool
35038fd1498Szrj     operator!=(const _List_iterator<_Val>& __x,
35138fd1498Szrj 	       const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
35238fd1498Szrj     { return __x._M_node != __y._M_node; }
35338fd1498Szrj 
35438fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CXX11
35538fd1498Szrj   /// See bits/stl_deque.h's _Deque_base for an explanation.
35638fd1498Szrj   template<typename _Tp, typename _Alloc>
35738fd1498Szrj     class _List_base
35838fd1498Szrj     {
35938fd1498Szrj     protected:
36038fd1498Szrj       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
36138fd1498Szrj 	rebind<_Tp>::other				_Tp_alloc_type;
36238fd1498Szrj       typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type>	_Tp_alloc_traits;
36338fd1498Szrj       typedef typename _Tp_alloc_traits::template
36438fd1498Szrj 	rebind<_List_node<_Tp> >::other _Node_alloc_type;
36538fd1498Szrj       typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
36638fd1498Szrj 
36738fd1498Szrj #if !_GLIBCXX_INLINE_VERSION
36838fd1498Szrj       static size_t
36938fd1498Szrj       _S_distance(const __detail::_List_node_base* __first,
37038fd1498Szrj 		  const __detail::_List_node_base* __last)
37138fd1498Szrj       {
37238fd1498Szrj 	size_t __n = 0;
37338fd1498Szrj 	while (__first != __last)
37438fd1498Szrj 	  {
37538fd1498Szrj 	    __first = __first->_M_next;
37638fd1498Szrj 	    ++__n;
37738fd1498Szrj 	  }
37838fd1498Szrj 	return __n;
37938fd1498Szrj       }
38038fd1498Szrj #endif
38138fd1498Szrj 
38238fd1498Szrj       struct _List_impl
38338fd1498Szrj       : public _Node_alloc_type
38438fd1498Szrj       {
38538fd1498Szrj 	__detail::_List_node_header _M_node;
38638fd1498Szrj 
387*58e805e6Szrj 	_List_impl() _GLIBCXX_NOEXCEPT_IF(
388*58e805e6Szrj 	    is_nothrow_default_constructible<_Node_alloc_type>::value)
38938fd1498Szrj 	: _Node_alloc_type()
39038fd1498Szrj 	{ }
39138fd1498Szrj 
39238fd1498Szrj 	_List_impl(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT
39338fd1498Szrj 	: _Node_alloc_type(__a)
39438fd1498Szrj 	{ }
39538fd1498Szrj 
39638fd1498Szrj #if __cplusplus >= 201103L
39738fd1498Szrj 	_List_impl(_List_impl&&) = default;
39838fd1498Szrj 
39938fd1498Szrj 	_List_impl(_Node_alloc_type&& __a, _List_impl&& __x)
40038fd1498Szrj 	: _Node_alloc_type(std::move(__a)), _M_node(std::move(__x._M_node))
40138fd1498Szrj 	{ }
40238fd1498Szrj 
40338fd1498Szrj 	_List_impl(_Node_alloc_type&& __a) noexcept
40438fd1498Szrj 	: _Node_alloc_type(std::move(__a))
40538fd1498Szrj 	{ }
40638fd1498Szrj #endif
40738fd1498Szrj       };
40838fd1498Szrj 
40938fd1498Szrj       _List_impl _M_impl;
41038fd1498Szrj 
41138fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
41238fd1498Szrj       size_t _M_get_size() const { return _M_impl._M_node._M_size; }
41338fd1498Szrj 
41438fd1498Szrj       void _M_set_size(size_t __n) { _M_impl._M_node._M_size = __n; }
41538fd1498Szrj 
41638fd1498Szrj       void _M_inc_size(size_t __n) { _M_impl._M_node._M_size += __n; }
41738fd1498Szrj 
41838fd1498Szrj       void _M_dec_size(size_t __n) { _M_impl._M_node._M_size -= __n; }
41938fd1498Szrj 
42038fd1498Szrj # if !_GLIBCXX_INLINE_VERSION
42138fd1498Szrj       size_t
42238fd1498Szrj       _M_distance(const __detail::_List_node_base* __first,
42338fd1498Szrj 		  const __detail::_List_node_base* __last) const
42438fd1498Szrj       { return _S_distance(__first, __last); }
42538fd1498Szrj 
42638fd1498Szrj       // return the stored size
42738fd1498Szrj       size_t _M_node_count() const { return _M_get_size(); }
42838fd1498Szrj # endif
42938fd1498Szrj #else
43038fd1498Szrj       // dummy implementations used when the size is not stored
43138fd1498Szrj       size_t _M_get_size() const { return 0; }
43238fd1498Szrj       void _M_set_size(size_t) { }
43338fd1498Szrj       void _M_inc_size(size_t) { }
43438fd1498Szrj       void _M_dec_size(size_t) { }
43538fd1498Szrj 
43638fd1498Szrj # if !_GLIBCXX_INLINE_VERSION
43738fd1498Szrj       size_t _M_distance(const void*, const void*) const { return 0; }
43838fd1498Szrj 
43938fd1498Szrj       // count the number of nodes
44038fd1498Szrj       size_t _M_node_count() const
44138fd1498Szrj       {
44238fd1498Szrj 	return _S_distance(_M_impl._M_node._M_next,
44338fd1498Szrj 			   std::__addressof(_M_impl._M_node));
44438fd1498Szrj       }
44538fd1498Szrj # endif
44638fd1498Szrj #endif
44738fd1498Szrj 
44838fd1498Szrj       typename _Node_alloc_traits::pointer
44938fd1498Szrj       _M_get_node()
45038fd1498Szrj       { return _Node_alloc_traits::allocate(_M_impl, 1); }
45138fd1498Szrj 
45238fd1498Szrj       void
45338fd1498Szrj       _M_put_node(typename _Node_alloc_traits::pointer __p) _GLIBCXX_NOEXCEPT
45438fd1498Szrj       { _Node_alloc_traits::deallocate(_M_impl, __p, 1); }
45538fd1498Szrj 
45638fd1498Szrj   public:
45738fd1498Szrj       typedef _Alloc allocator_type;
45838fd1498Szrj 
45938fd1498Szrj       _Node_alloc_type&
46038fd1498Szrj       _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
46138fd1498Szrj       { return _M_impl; }
46238fd1498Szrj 
46338fd1498Szrj       const _Node_alloc_type&
46438fd1498Szrj       _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
46538fd1498Szrj       { return _M_impl; }
46638fd1498Szrj 
46738fd1498Szrj #if __cplusplus >= 201103L
46838fd1498Szrj       _List_base() = default;
46938fd1498Szrj #else
47038fd1498Szrj       _List_base() { }
47138fd1498Szrj #endif
47238fd1498Szrj 
47338fd1498Szrj       _List_base(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT
47438fd1498Szrj       : _M_impl(__a)
47538fd1498Szrj       { }
47638fd1498Szrj 
47738fd1498Szrj #if __cplusplus >= 201103L
47838fd1498Szrj       _List_base(_List_base&&) = default;
47938fd1498Szrj 
48038fd1498Szrj # if !_GLIBCXX_INLINE_VERSION
48138fd1498Szrj       _List_base(_List_base&& __x, _Node_alloc_type&& __a)
48238fd1498Szrj       : _M_impl(std::move(__a))
48338fd1498Szrj       {
48438fd1498Szrj 	if (__x._M_get_Node_allocator() == _M_get_Node_allocator())
48538fd1498Szrj 	  _M_move_nodes(std::move(__x));
48638fd1498Szrj 	// else caller must move individual elements.
48738fd1498Szrj       }
48838fd1498Szrj # endif
48938fd1498Szrj 
49038fd1498Szrj       // Used when allocator is_always_equal.
49138fd1498Szrj       _List_base(_Node_alloc_type&& __a, _List_base&& __x)
49238fd1498Szrj       : _M_impl(std::move(__a), std::move(__x._M_impl))
49338fd1498Szrj       { }
49438fd1498Szrj 
49538fd1498Szrj       // Used when allocator !is_always_equal.
49638fd1498Szrj       _List_base(_Node_alloc_type&& __a)
49738fd1498Szrj       : _M_impl(std::move(__a))
49838fd1498Szrj       { }
49938fd1498Szrj 
50038fd1498Szrj       void
50138fd1498Szrj       _M_move_nodes(_List_base&& __x)
50238fd1498Szrj       { _M_impl._M_node._M_move_nodes(std::move(__x._M_impl._M_node)); }
50338fd1498Szrj #endif
50438fd1498Szrj 
50538fd1498Szrj       // This is what actually destroys the list.
50638fd1498Szrj       ~_List_base() _GLIBCXX_NOEXCEPT
50738fd1498Szrj       { _M_clear(); }
50838fd1498Szrj 
50938fd1498Szrj       void
51038fd1498Szrj       _M_clear() _GLIBCXX_NOEXCEPT;
51138fd1498Szrj 
51238fd1498Szrj       void
51338fd1498Szrj       _M_init() _GLIBCXX_NOEXCEPT
51438fd1498Szrj       { this->_M_impl._M_node._M_init(); }
51538fd1498Szrj     };
51638fd1498Szrj 
51738fd1498Szrj   /**
51838fd1498Szrj    *  @brief A standard container with linear time access to elements,
51938fd1498Szrj    *  and fixed time insertion/deletion at any point in the sequence.
52038fd1498Szrj    *
52138fd1498Szrj    *  @ingroup sequences
52238fd1498Szrj    *
52338fd1498Szrj    *  @tparam _Tp  Type of element.
52438fd1498Szrj    *  @tparam _Alloc  Allocator type, defaults to allocator<_Tp>.
52538fd1498Szrj    *
52638fd1498Szrj    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
52738fd1498Szrj    *  <a href="tables.html#66">reversible container</a>, and a
52838fd1498Szrj    *  <a href="tables.html#67">sequence</a>, including the
52938fd1498Szrj    *  <a href="tables.html#68">optional sequence requirements</a> with the
53038fd1498Szrj    *  %exception of @c at and @c operator[].
53138fd1498Szrj    *
53238fd1498Szrj    *  This is a @e doubly @e linked %list.  Traversal up and down the
53338fd1498Szrj    *  %list requires linear time, but adding and removing elements (or
53438fd1498Szrj    *  @e nodes) is done in constant time, regardless of where the
53538fd1498Szrj    *  change takes place.  Unlike std::vector and std::deque,
53638fd1498Szrj    *  random-access iterators are not provided, so subscripting ( @c
53738fd1498Szrj    *  [] ) access is not allowed.  For algorithms which only need
53838fd1498Szrj    *  sequential access, this lack makes no difference.
53938fd1498Szrj    *
54038fd1498Szrj    *  Also unlike the other standard containers, std::list provides
54138fd1498Szrj    *  specialized algorithms %unique to linked lists, such as
54238fd1498Szrj    *  splicing, sorting, and in-place reversal.
54338fd1498Szrj    *
54438fd1498Szrj    *  A couple points on memory allocation for list<Tp>:
54538fd1498Szrj    *
54638fd1498Szrj    *  First, we never actually allocate a Tp, we allocate
54738fd1498Szrj    *  List_node<Tp>'s and trust [20.1.5]/4 to DTRT.  This is to ensure
54838fd1498Szrj    *  that after elements from %list<X,Alloc1> are spliced into
54938fd1498Szrj    *  %list<X,Alloc2>, destroying the memory of the second %list is a
55038fd1498Szrj    *  valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
55138fd1498Szrj    *
55238fd1498Szrj    *  Second, a %list conceptually represented as
55338fd1498Szrj    *  @code
55438fd1498Szrj    *    A <---> B <---> C <---> D
55538fd1498Szrj    *  @endcode
55638fd1498Szrj    *  is actually circular; a link exists between A and D.  The %list
55738fd1498Szrj    *  class holds (as its only data member) a private list::iterator
55838fd1498Szrj    *  pointing to @e D, not to @e A!  To get to the head of the %list,
55938fd1498Szrj    *  we start at the tail and move forward by one.  When this member
56038fd1498Szrj    *  iterator's next/previous pointers refer to itself, the %list is
56138fd1498Szrj    *  %empty.
56238fd1498Szrj   */
56338fd1498Szrj   template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
56438fd1498Szrj     class list : protected _List_base<_Tp, _Alloc>
56538fd1498Szrj     {
56638fd1498Szrj #ifdef _GLIBCXX_CONCEPT_CHECKS
56738fd1498Szrj       // concept requirements
56838fd1498Szrj       typedef typename _Alloc::value_type		_Alloc_value_type;
56938fd1498Szrj # if __cplusplus < 201103L
57038fd1498Szrj       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
57138fd1498Szrj # endif
57238fd1498Szrj       __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
57338fd1498Szrj #endif
57438fd1498Szrj 
57538fd1498Szrj #if __cplusplus >= 201103L
57638fd1498Szrj       static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value,
57738fd1498Szrj 	  "std::list must have a non-const, non-volatile value_type");
57838fd1498Szrj # ifdef __STRICT_ANSI__
57938fd1498Szrj       static_assert(is_same<typename _Alloc::value_type, _Tp>::value,
58038fd1498Szrj 	  "std::list must have the same value_type as its allocator");
58138fd1498Szrj # endif
58238fd1498Szrj #endif
58338fd1498Szrj 
58438fd1498Szrj       typedef _List_base<_Tp, _Alloc>			_Base;
58538fd1498Szrj       typedef typename _Base::_Tp_alloc_type		_Tp_alloc_type;
58638fd1498Szrj       typedef typename _Base::_Tp_alloc_traits		_Tp_alloc_traits;
58738fd1498Szrj       typedef typename _Base::_Node_alloc_type		_Node_alloc_type;
58838fd1498Szrj       typedef typename _Base::_Node_alloc_traits	_Node_alloc_traits;
58938fd1498Szrj 
59038fd1498Szrj     public:
59138fd1498Szrj       typedef _Tp					 value_type;
59238fd1498Szrj       typedef typename _Tp_alloc_traits::pointer	 pointer;
59338fd1498Szrj       typedef typename _Tp_alloc_traits::const_pointer	 const_pointer;
59438fd1498Szrj       typedef typename _Tp_alloc_traits::reference	 reference;
59538fd1498Szrj       typedef typename _Tp_alloc_traits::const_reference const_reference;
59638fd1498Szrj       typedef _List_iterator<_Tp>			 iterator;
59738fd1498Szrj       typedef _List_const_iterator<_Tp>			 const_iterator;
59838fd1498Szrj       typedef std::reverse_iterator<const_iterator>	 const_reverse_iterator;
59938fd1498Szrj       typedef std::reverse_iterator<iterator>		 reverse_iterator;
60038fd1498Szrj       typedef size_t					 size_type;
60138fd1498Szrj       typedef ptrdiff_t					 difference_type;
60238fd1498Szrj       typedef _Alloc					 allocator_type;
60338fd1498Szrj 
60438fd1498Szrj     protected:
60538fd1498Szrj       // Note that pointers-to-_Node's can be ctor-converted to
60638fd1498Szrj       // iterator types.
60738fd1498Szrj       typedef _List_node<_Tp>				 _Node;
60838fd1498Szrj 
60938fd1498Szrj       using _Base::_M_impl;
61038fd1498Szrj       using _Base::_M_put_node;
61138fd1498Szrj       using _Base::_M_get_node;
61238fd1498Szrj       using _Base::_M_get_Node_allocator;
61338fd1498Szrj 
61438fd1498Szrj       /**
61538fd1498Szrj        *  @param  __args  An instance of user data.
61638fd1498Szrj        *
61738fd1498Szrj        *  Allocates space for a new node and constructs a copy of
61838fd1498Szrj        *  @a __args in it.
61938fd1498Szrj        */
62038fd1498Szrj #if __cplusplus < 201103L
62138fd1498Szrj       _Node*
62238fd1498Szrj       _M_create_node(const value_type& __x)
62338fd1498Szrj       {
62438fd1498Szrj 	_Node* __p = this->_M_get_node();
62538fd1498Szrj 	__try
62638fd1498Szrj 	  {
62738fd1498Szrj 	    _Tp_alloc_type __alloc(_M_get_Node_allocator());
62838fd1498Szrj 	    __alloc.construct(__p->_M_valptr(), __x);
62938fd1498Szrj 	  }
63038fd1498Szrj 	__catch(...)
63138fd1498Szrj 	  {
63238fd1498Szrj 	    _M_put_node(__p);
63338fd1498Szrj 	    __throw_exception_again;
63438fd1498Szrj 	  }
63538fd1498Szrj 	return __p;
63638fd1498Szrj       }
63738fd1498Szrj #else
63838fd1498Szrj       template<typename... _Args>
63938fd1498Szrj 	_Node*
64038fd1498Szrj 	_M_create_node(_Args&&... __args)
64138fd1498Szrj 	{
64238fd1498Szrj 	  auto __p = this->_M_get_node();
64338fd1498Szrj 	  auto& __alloc = _M_get_Node_allocator();
64438fd1498Szrj 	  __allocated_ptr<_Node_alloc_type> __guard{__alloc, __p};
64538fd1498Szrj 	  _Node_alloc_traits::construct(__alloc, __p->_M_valptr(),
64638fd1498Szrj 					std::forward<_Args>(__args)...);
64738fd1498Szrj 	  __guard = nullptr;
64838fd1498Szrj 	  return __p;
64938fd1498Szrj 	}
65038fd1498Szrj #endif
65138fd1498Szrj 
65238fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
65338fd1498Szrj       static size_t
65438fd1498Szrj       _S_distance(const_iterator __first, const_iterator __last)
65538fd1498Szrj       { return std::distance(__first, __last); }
65638fd1498Szrj 
65738fd1498Szrj       // return the stored size
65838fd1498Szrj       size_t
65938fd1498Szrj       _M_node_count() const
66038fd1498Szrj       { return this->_M_get_size(); }
66138fd1498Szrj #else
66238fd1498Szrj       // dummy implementations used when the size is not stored
66338fd1498Szrj       static size_t
66438fd1498Szrj       _S_distance(const_iterator, const_iterator)
66538fd1498Szrj       { return 0; }
66638fd1498Szrj 
66738fd1498Szrj       // count the number of nodes
66838fd1498Szrj       size_t
66938fd1498Szrj       _M_node_count() const
67038fd1498Szrj       { return std::distance(begin(), end()); }
67138fd1498Szrj #endif
67238fd1498Szrj 
67338fd1498Szrj     public:
67438fd1498Szrj       // [23.2.2.1] construct/copy/destroy
67538fd1498Szrj       // (assign() and get_allocator() are also listed in this section)
67638fd1498Szrj 
67738fd1498Szrj       /**
67838fd1498Szrj        *  @brief  Creates a %list with no elements.
67938fd1498Szrj        */
68038fd1498Szrj #if __cplusplus >= 201103L
68138fd1498Szrj       list() = default;
68238fd1498Szrj #else
68338fd1498Szrj       list() { }
68438fd1498Szrj #endif
68538fd1498Szrj 
68638fd1498Szrj       /**
68738fd1498Szrj        *  @brief  Creates a %list with no elements.
68838fd1498Szrj        *  @param  __a  An allocator object.
68938fd1498Szrj        */
69038fd1498Szrj       explicit
69138fd1498Szrj       list(const allocator_type& __a) _GLIBCXX_NOEXCEPT
69238fd1498Szrj       : _Base(_Node_alloc_type(__a)) { }
69338fd1498Szrj 
69438fd1498Szrj #if __cplusplus >= 201103L
69538fd1498Szrj       /**
69638fd1498Szrj        *  @brief  Creates a %list with default constructed elements.
69738fd1498Szrj        *  @param  __n  The number of elements to initially create.
69838fd1498Szrj        *  @param  __a  An allocator object.
69938fd1498Szrj        *
70038fd1498Szrj        *  This constructor fills the %list with @a __n default
70138fd1498Szrj        *  constructed elements.
70238fd1498Szrj        */
70338fd1498Szrj       explicit
70438fd1498Szrj       list(size_type __n, const allocator_type& __a = allocator_type())
70538fd1498Szrj       : _Base(_Node_alloc_type(__a))
70638fd1498Szrj       { _M_default_initialize(__n); }
70738fd1498Szrj 
70838fd1498Szrj       /**
70938fd1498Szrj        *  @brief  Creates a %list with copies of an exemplar element.
71038fd1498Szrj        *  @param  __n  The number of elements to initially create.
71138fd1498Szrj        *  @param  __value  An element to copy.
71238fd1498Szrj        *  @param  __a  An allocator object.
71338fd1498Szrj        *
71438fd1498Szrj        *  This constructor fills the %list with @a __n copies of @a __value.
71538fd1498Szrj        */
71638fd1498Szrj       list(size_type __n, const value_type& __value,
71738fd1498Szrj 	   const allocator_type& __a = allocator_type())
71838fd1498Szrj       : _Base(_Node_alloc_type(__a))
71938fd1498Szrj       { _M_fill_initialize(__n, __value); }
72038fd1498Szrj #else
72138fd1498Szrj       /**
72238fd1498Szrj        *  @brief  Creates a %list with copies of an exemplar element.
72338fd1498Szrj        *  @param  __n  The number of elements to initially create.
72438fd1498Szrj        *  @param  __value  An element to copy.
72538fd1498Szrj        *  @param  __a  An allocator object.
72638fd1498Szrj        *
72738fd1498Szrj        *  This constructor fills the %list with @a __n copies of @a __value.
72838fd1498Szrj        */
72938fd1498Szrj       explicit
73038fd1498Szrj       list(size_type __n, const value_type& __value = value_type(),
73138fd1498Szrj 	   const allocator_type& __a = allocator_type())
73238fd1498Szrj       : _Base(_Node_alloc_type(__a))
73338fd1498Szrj       { _M_fill_initialize(__n, __value); }
73438fd1498Szrj #endif
73538fd1498Szrj 
73638fd1498Szrj       /**
73738fd1498Szrj        *  @brief  %List copy constructor.
73838fd1498Szrj        *  @param  __x  A %list of identical element and allocator types.
73938fd1498Szrj        *
74038fd1498Szrj        *  The newly-created %list uses a copy of the allocation object used
74138fd1498Szrj        *  by @a __x (unless the allocator traits dictate a different object).
74238fd1498Szrj        */
74338fd1498Szrj       list(const list& __x)
74438fd1498Szrj       : _Base(_Node_alloc_traits::
74538fd1498Szrj 	      _S_select_on_copy(__x._M_get_Node_allocator()))
74638fd1498Szrj       { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
74738fd1498Szrj 
74838fd1498Szrj #if __cplusplus >= 201103L
74938fd1498Szrj       /**
75038fd1498Szrj        *  @brief  %List move constructor.
75138fd1498Szrj        *
75238fd1498Szrj        *  The newly-created %list contains the exact contents of the moved
75338fd1498Szrj        *  instance. The contents of the moved instance are a valid, but
75438fd1498Szrj        *  unspecified %list.
75538fd1498Szrj        */
75638fd1498Szrj       list(list&&) = default;
75738fd1498Szrj 
75838fd1498Szrj       /**
75938fd1498Szrj        *  @brief  Builds a %list from an initializer_list
76038fd1498Szrj        *  @param  __l  An initializer_list of value_type.
76138fd1498Szrj        *  @param  __a  An allocator object.
76238fd1498Szrj        *
76338fd1498Szrj        *  Create a %list consisting of copies of the elements in the
76438fd1498Szrj        *  initializer_list @a __l.  This is linear in __l.size().
76538fd1498Szrj        */
76638fd1498Szrj       list(initializer_list<value_type> __l,
76738fd1498Szrj 	   const allocator_type& __a = allocator_type())
76838fd1498Szrj       : _Base(_Node_alloc_type(__a))
76938fd1498Szrj       { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); }
77038fd1498Szrj 
77138fd1498Szrj       list(const list& __x, const allocator_type& __a)
77238fd1498Szrj       : _Base(_Node_alloc_type(__a))
77338fd1498Szrj       { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
77438fd1498Szrj 
77538fd1498Szrj     private:
77638fd1498Szrj       list(list&& __x, const allocator_type& __a, true_type) noexcept
77738fd1498Szrj       : _Base(_Node_alloc_type(__a), std::move(__x))
77838fd1498Szrj       { }
77938fd1498Szrj 
78038fd1498Szrj       list(list&& __x, const allocator_type& __a, false_type)
78138fd1498Szrj       : _Base(_Node_alloc_type(__a))
78238fd1498Szrj       {
78338fd1498Szrj 	if (__x._M_get_Node_allocator() == this->_M_get_Node_allocator())
78438fd1498Szrj 	  this->_M_move_nodes(std::move(__x));
78538fd1498Szrj 	else
78638fd1498Szrj 	  insert(begin(), std::__make_move_if_noexcept_iterator(__x.begin()),
78738fd1498Szrj 			  std::__make_move_if_noexcept_iterator(__x.end()));
78838fd1498Szrj       }
78938fd1498Szrj 
79038fd1498Szrj     public:
79138fd1498Szrj       list(list&& __x, const allocator_type& __a)
79238fd1498Szrj       noexcept(_Node_alloc_traits::_S_always_equal())
79338fd1498Szrj       : list(std::move(__x), __a,
79438fd1498Szrj 	     typename _Node_alloc_traits::is_always_equal{})
79538fd1498Szrj       { }
79638fd1498Szrj #endif
79738fd1498Szrj 
79838fd1498Szrj       /**
79938fd1498Szrj        *  @brief  Builds a %list from a range.
80038fd1498Szrj        *  @param  __first  An input iterator.
80138fd1498Szrj        *  @param  __last  An input iterator.
80238fd1498Szrj        *  @param  __a  An allocator object.
80338fd1498Szrj        *
80438fd1498Szrj        *  Create a %list consisting of copies of the elements from
80538fd1498Szrj        *  [@a __first,@a __last).  This is linear in N (where N is
80638fd1498Szrj        *  distance(@a __first,@a __last)).
80738fd1498Szrj        */
80838fd1498Szrj #if __cplusplus >= 201103L
80938fd1498Szrj       template<typename _InputIterator,
81038fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
81138fd1498Szrj 	list(_InputIterator __first, _InputIterator __last,
81238fd1498Szrj 	     const allocator_type& __a = allocator_type())
81338fd1498Szrj 	: _Base(_Node_alloc_type(__a))
81438fd1498Szrj 	{ _M_initialize_dispatch(__first, __last, __false_type()); }
81538fd1498Szrj #else
81638fd1498Szrj       template<typename _InputIterator>
81738fd1498Szrj 	list(_InputIterator __first, _InputIterator __last,
81838fd1498Szrj 	     const allocator_type& __a = allocator_type())
81938fd1498Szrj 	: _Base(_Node_alloc_type(__a))
82038fd1498Szrj 	{
82138fd1498Szrj 	  // Check whether it's an integral type.  If so, it's not an iterator.
82238fd1498Szrj 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
82338fd1498Szrj 	  _M_initialize_dispatch(__first, __last, _Integral());
82438fd1498Szrj 	}
82538fd1498Szrj #endif
82638fd1498Szrj 
82738fd1498Szrj #if __cplusplus >= 201103L
82838fd1498Szrj       /**
82938fd1498Szrj        *  No explicit dtor needed as the _Base dtor takes care of
83038fd1498Szrj        *  things.  The _Base dtor only erases the elements, and note
83138fd1498Szrj        *  that if the elements themselves are pointers, the pointed-to
83238fd1498Szrj        *  memory is not touched in any way.  Managing the pointer is
83338fd1498Szrj        *  the user's responsibility.
83438fd1498Szrj        */
83538fd1498Szrj       ~list() = default;
83638fd1498Szrj #endif
83738fd1498Szrj 
83838fd1498Szrj       /**
83938fd1498Szrj        *  @brief  %List assignment operator.
84038fd1498Szrj        *  @param  __x  A %list of identical element and allocator types.
84138fd1498Szrj        *
84238fd1498Szrj        *  All the elements of @a __x are copied.
84338fd1498Szrj        *
84438fd1498Szrj        *  Whether the allocator is copied depends on the allocator traits.
84538fd1498Szrj        */
84638fd1498Szrj       list&
84738fd1498Szrj       operator=(const list& __x);
84838fd1498Szrj 
84938fd1498Szrj #if __cplusplus >= 201103L
85038fd1498Szrj       /**
85138fd1498Szrj        *  @brief  %List move assignment operator.
85238fd1498Szrj        *  @param  __x  A %list of identical element and allocator types.
85338fd1498Szrj        *
85438fd1498Szrj        *  The contents of @a __x are moved into this %list (without copying).
85538fd1498Szrj        *
85638fd1498Szrj        *  Afterwards @a __x is a valid, but unspecified %list
85738fd1498Szrj        *
85838fd1498Szrj        *  Whether the allocator is moved depends on the allocator traits.
85938fd1498Szrj        */
86038fd1498Szrj       list&
86138fd1498Szrj       operator=(list&& __x)
86238fd1498Szrj       noexcept(_Node_alloc_traits::_S_nothrow_move())
86338fd1498Szrj       {
86438fd1498Szrj 	constexpr bool __move_storage =
86538fd1498Szrj 	  _Node_alloc_traits::_S_propagate_on_move_assign()
86638fd1498Szrj 	  || _Node_alloc_traits::_S_always_equal();
86738fd1498Szrj 	_M_move_assign(std::move(__x), __bool_constant<__move_storage>());
86838fd1498Szrj 	return *this;
86938fd1498Szrj       }
87038fd1498Szrj 
87138fd1498Szrj       /**
87238fd1498Szrj        *  @brief  %List initializer list assignment operator.
87338fd1498Szrj        *  @param  __l  An initializer_list of value_type.
87438fd1498Szrj        *
87538fd1498Szrj        *  Replace the contents of the %list with copies of the elements
87638fd1498Szrj        *  in the initializer_list @a __l.  This is linear in l.size().
87738fd1498Szrj        */
87838fd1498Szrj       list&
87938fd1498Szrj       operator=(initializer_list<value_type> __l)
88038fd1498Szrj       {
88138fd1498Szrj 	this->assign(__l.begin(), __l.end());
88238fd1498Szrj 	return *this;
88338fd1498Szrj       }
88438fd1498Szrj #endif
88538fd1498Szrj 
88638fd1498Szrj       /**
88738fd1498Szrj        *  @brief  Assigns a given value to a %list.
88838fd1498Szrj        *  @param  __n  Number of elements to be assigned.
88938fd1498Szrj        *  @param  __val  Value to be assigned.
89038fd1498Szrj        *
89138fd1498Szrj        *  This function fills a %list with @a __n copies of the given
89238fd1498Szrj        *  value.  Note that the assignment completely changes the %list
89338fd1498Szrj        *  and that the resulting %list's size is the same as the number
89438fd1498Szrj        *  of elements assigned.
89538fd1498Szrj        */
89638fd1498Szrj       void
89738fd1498Szrj       assign(size_type __n, const value_type& __val)
89838fd1498Szrj       { _M_fill_assign(__n, __val); }
89938fd1498Szrj 
90038fd1498Szrj       /**
90138fd1498Szrj        *  @brief  Assigns a range to a %list.
90238fd1498Szrj        *  @param  __first  An input iterator.
90338fd1498Szrj        *  @param  __last   An input iterator.
90438fd1498Szrj        *
90538fd1498Szrj        *  This function fills a %list with copies of the elements in the
90638fd1498Szrj        *  range [@a __first,@a __last).
90738fd1498Szrj        *
90838fd1498Szrj        *  Note that the assignment completely changes the %list and
90938fd1498Szrj        *  that the resulting %list's size is the same as the number of
91038fd1498Szrj        *  elements assigned.
91138fd1498Szrj        */
91238fd1498Szrj #if __cplusplus >= 201103L
91338fd1498Szrj       template<typename _InputIterator,
91438fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
91538fd1498Szrj 	void
91638fd1498Szrj 	assign(_InputIterator __first, _InputIterator __last)
91738fd1498Szrj 	{ _M_assign_dispatch(__first, __last, __false_type()); }
91838fd1498Szrj #else
91938fd1498Szrj       template<typename _InputIterator>
92038fd1498Szrj 	void
92138fd1498Szrj 	assign(_InputIterator __first, _InputIterator __last)
92238fd1498Szrj 	{
92338fd1498Szrj 	  // Check whether it's an integral type.  If so, it's not an iterator.
92438fd1498Szrj 	  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
92538fd1498Szrj 	  _M_assign_dispatch(__first, __last, _Integral());
92638fd1498Szrj 	}
92738fd1498Szrj #endif
92838fd1498Szrj 
92938fd1498Szrj #if __cplusplus >= 201103L
93038fd1498Szrj       /**
93138fd1498Szrj        *  @brief  Assigns an initializer_list to a %list.
93238fd1498Szrj        *  @param  __l  An initializer_list of value_type.
93338fd1498Szrj        *
93438fd1498Szrj        *  Replace the contents of the %list with copies of the elements
93538fd1498Szrj        *  in the initializer_list @a __l.  This is linear in __l.size().
93638fd1498Szrj        */
93738fd1498Szrj       void
93838fd1498Szrj       assign(initializer_list<value_type> __l)
93938fd1498Szrj       { this->_M_assign_dispatch(__l.begin(), __l.end(), __false_type()); }
94038fd1498Szrj #endif
94138fd1498Szrj 
94238fd1498Szrj       /// Get a copy of the memory allocation object.
94338fd1498Szrj       allocator_type
94438fd1498Szrj       get_allocator() const _GLIBCXX_NOEXCEPT
94538fd1498Szrj       { return allocator_type(_Base::_M_get_Node_allocator()); }
94638fd1498Szrj 
94738fd1498Szrj       // iterators
94838fd1498Szrj       /**
94938fd1498Szrj        *  Returns a read/write iterator that points to the first element in the
95038fd1498Szrj        *  %list.  Iteration is done in ordinary element order.
95138fd1498Szrj        */
95238fd1498Szrj       iterator
95338fd1498Szrj       begin() _GLIBCXX_NOEXCEPT
95438fd1498Szrj       { return iterator(this->_M_impl._M_node._M_next); }
95538fd1498Szrj 
95638fd1498Szrj       /**
95738fd1498Szrj        *  Returns a read-only (constant) iterator that points to the
95838fd1498Szrj        *  first element in the %list.  Iteration is done in ordinary
95938fd1498Szrj        *  element order.
96038fd1498Szrj        */
96138fd1498Szrj       const_iterator
96238fd1498Szrj       begin() const _GLIBCXX_NOEXCEPT
96338fd1498Szrj       { return const_iterator(this->_M_impl._M_node._M_next); }
96438fd1498Szrj 
96538fd1498Szrj       /**
96638fd1498Szrj        *  Returns a read/write iterator that points one past the last
96738fd1498Szrj        *  element in the %list.  Iteration is done in ordinary element
96838fd1498Szrj        *  order.
96938fd1498Szrj        */
97038fd1498Szrj       iterator
97138fd1498Szrj       end() _GLIBCXX_NOEXCEPT
97238fd1498Szrj       { return iterator(&this->_M_impl._M_node); }
97338fd1498Szrj 
97438fd1498Szrj       /**
97538fd1498Szrj        *  Returns a read-only (constant) iterator that points one past
97638fd1498Szrj        *  the last element in the %list.  Iteration is done in ordinary
97738fd1498Szrj        *  element order.
97838fd1498Szrj        */
97938fd1498Szrj       const_iterator
98038fd1498Szrj       end() const _GLIBCXX_NOEXCEPT
98138fd1498Szrj       { return const_iterator(&this->_M_impl._M_node); }
98238fd1498Szrj 
98338fd1498Szrj       /**
98438fd1498Szrj        *  Returns a read/write reverse iterator that points to the last
98538fd1498Szrj        *  element in the %list.  Iteration is done in reverse element
98638fd1498Szrj        *  order.
98738fd1498Szrj        */
98838fd1498Szrj       reverse_iterator
98938fd1498Szrj       rbegin() _GLIBCXX_NOEXCEPT
99038fd1498Szrj       { return reverse_iterator(end()); }
99138fd1498Szrj 
99238fd1498Szrj       /**
99338fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to
99438fd1498Szrj        *  the last element in the %list.  Iteration is done in reverse
99538fd1498Szrj        *  element order.
99638fd1498Szrj        */
99738fd1498Szrj       const_reverse_iterator
99838fd1498Szrj       rbegin() const _GLIBCXX_NOEXCEPT
99938fd1498Szrj       { return const_reverse_iterator(end()); }
100038fd1498Szrj 
100138fd1498Szrj       /**
100238fd1498Szrj        *  Returns a read/write reverse iterator that points to one
100338fd1498Szrj        *  before the first element in the %list.  Iteration is done in
100438fd1498Szrj        *  reverse element order.
100538fd1498Szrj        */
100638fd1498Szrj       reverse_iterator
100738fd1498Szrj       rend() _GLIBCXX_NOEXCEPT
100838fd1498Szrj       { return reverse_iterator(begin()); }
100938fd1498Szrj 
101038fd1498Szrj       /**
101138fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to one
101238fd1498Szrj        *  before the first element in the %list.  Iteration is done in reverse
101338fd1498Szrj        *  element order.
101438fd1498Szrj        */
101538fd1498Szrj       const_reverse_iterator
101638fd1498Szrj       rend() const _GLIBCXX_NOEXCEPT
101738fd1498Szrj       { return const_reverse_iterator(begin()); }
101838fd1498Szrj 
101938fd1498Szrj #if __cplusplus >= 201103L
102038fd1498Szrj       /**
102138fd1498Szrj        *  Returns a read-only (constant) iterator that points to the
102238fd1498Szrj        *  first element in the %list.  Iteration is done in ordinary
102338fd1498Szrj        *  element order.
102438fd1498Szrj        */
102538fd1498Szrj       const_iterator
102638fd1498Szrj       cbegin() const noexcept
102738fd1498Szrj       { return const_iterator(this->_M_impl._M_node._M_next); }
102838fd1498Szrj 
102938fd1498Szrj       /**
103038fd1498Szrj        *  Returns a read-only (constant) iterator that points one past
103138fd1498Szrj        *  the last element in the %list.  Iteration is done in ordinary
103238fd1498Szrj        *  element order.
103338fd1498Szrj        */
103438fd1498Szrj       const_iterator
103538fd1498Szrj       cend() const noexcept
103638fd1498Szrj       { return const_iterator(&this->_M_impl._M_node); }
103738fd1498Szrj 
103838fd1498Szrj       /**
103938fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to
104038fd1498Szrj        *  the last element in the %list.  Iteration is done in reverse
104138fd1498Szrj        *  element order.
104238fd1498Szrj        */
104338fd1498Szrj       const_reverse_iterator
104438fd1498Szrj       crbegin() const noexcept
104538fd1498Szrj       { return const_reverse_iterator(end()); }
104638fd1498Szrj 
104738fd1498Szrj       /**
104838fd1498Szrj        *  Returns a read-only (constant) reverse iterator that points to one
104938fd1498Szrj        *  before the first element in the %list.  Iteration is done in reverse
105038fd1498Szrj        *  element order.
105138fd1498Szrj        */
105238fd1498Szrj       const_reverse_iterator
105338fd1498Szrj       crend() const noexcept
105438fd1498Szrj       { return const_reverse_iterator(begin()); }
105538fd1498Szrj #endif
105638fd1498Szrj 
105738fd1498Szrj       // [23.2.2.2] capacity
105838fd1498Szrj       /**
105938fd1498Szrj        *  Returns true if the %list is empty.  (Thus begin() would equal
106038fd1498Szrj        *  end().)
106138fd1498Szrj        */
106238fd1498Szrj       bool
106338fd1498Szrj       empty() const _GLIBCXX_NOEXCEPT
106438fd1498Szrj       { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
106538fd1498Szrj 
106638fd1498Szrj       /**  Returns the number of elements in the %list.  */
106738fd1498Szrj       size_type
106838fd1498Szrj       size() const _GLIBCXX_NOEXCEPT
106938fd1498Szrj       { return _M_node_count(); }
107038fd1498Szrj 
107138fd1498Szrj       /**  Returns the size() of the largest possible %list.  */
107238fd1498Szrj       size_type
107338fd1498Szrj       max_size() const _GLIBCXX_NOEXCEPT
107438fd1498Szrj       { return _Node_alloc_traits::max_size(_M_get_Node_allocator()); }
107538fd1498Szrj 
107638fd1498Szrj #if __cplusplus >= 201103L
107738fd1498Szrj       /**
107838fd1498Szrj        *  @brief Resizes the %list to the specified number of elements.
107938fd1498Szrj        *  @param __new_size Number of elements the %list should contain.
108038fd1498Szrj        *
108138fd1498Szrj        *  This function will %resize the %list to the specified number
108238fd1498Szrj        *  of elements.  If the number is smaller than the %list's
108338fd1498Szrj        *  current size the %list is truncated, otherwise default
108438fd1498Szrj        *  constructed elements are appended.
108538fd1498Szrj        */
108638fd1498Szrj       void
108738fd1498Szrj       resize(size_type __new_size);
108838fd1498Szrj 
108938fd1498Szrj       /**
109038fd1498Szrj        *  @brief Resizes the %list to the specified number of elements.
109138fd1498Szrj        *  @param __new_size Number of elements the %list should contain.
109238fd1498Szrj        *  @param __x Data with which new elements should be populated.
109338fd1498Szrj        *
109438fd1498Szrj        *  This function will %resize the %list to the specified number
109538fd1498Szrj        *  of elements.  If the number is smaller than the %list's
109638fd1498Szrj        *  current size the %list is truncated, otherwise the %list is
109738fd1498Szrj        *  extended and new elements are populated with given data.
109838fd1498Szrj        */
109938fd1498Szrj       void
110038fd1498Szrj       resize(size_type __new_size, const value_type& __x);
110138fd1498Szrj #else
110238fd1498Szrj       /**
110338fd1498Szrj        *  @brief Resizes the %list to the specified number of elements.
110438fd1498Szrj        *  @param __new_size Number of elements the %list should contain.
110538fd1498Szrj        *  @param __x Data with which new elements should be populated.
110638fd1498Szrj        *
110738fd1498Szrj        *  This function will %resize the %list to the specified number
110838fd1498Szrj        *  of elements.  If the number is smaller than the %list's
110938fd1498Szrj        *  current size the %list is truncated, otherwise the %list is
111038fd1498Szrj        *  extended and new elements are populated with given data.
111138fd1498Szrj        */
111238fd1498Szrj       void
111338fd1498Szrj       resize(size_type __new_size, value_type __x = value_type());
111438fd1498Szrj #endif
111538fd1498Szrj 
111638fd1498Szrj       // element access
111738fd1498Szrj       /**
111838fd1498Szrj        *  Returns a read/write reference to the data at the first
111938fd1498Szrj        *  element of the %list.
112038fd1498Szrj        */
112138fd1498Szrj       reference
112238fd1498Szrj       front() _GLIBCXX_NOEXCEPT
112338fd1498Szrj       { return *begin(); }
112438fd1498Szrj 
112538fd1498Szrj       /**
112638fd1498Szrj        *  Returns a read-only (constant) reference to the data at the first
112738fd1498Szrj        *  element of the %list.
112838fd1498Szrj        */
112938fd1498Szrj       const_reference
113038fd1498Szrj       front() const _GLIBCXX_NOEXCEPT
113138fd1498Szrj       { return *begin(); }
113238fd1498Szrj 
113338fd1498Szrj       /**
113438fd1498Szrj        *  Returns a read/write reference to the data at the last element
113538fd1498Szrj        *  of the %list.
113638fd1498Szrj        */
113738fd1498Szrj       reference
113838fd1498Szrj       back() _GLIBCXX_NOEXCEPT
113938fd1498Szrj       {
114038fd1498Szrj 	iterator __tmp = end();
114138fd1498Szrj 	--__tmp;
114238fd1498Szrj 	return *__tmp;
114338fd1498Szrj       }
114438fd1498Szrj 
114538fd1498Szrj       /**
114638fd1498Szrj        *  Returns a read-only (constant) reference to the data at the last
114738fd1498Szrj        *  element of the %list.
114838fd1498Szrj        */
114938fd1498Szrj       const_reference
115038fd1498Szrj       back() const _GLIBCXX_NOEXCEPT
115138fd1498Szrj       {
115238fd1498Szrj 	const_iterator __tmp = end();
115338fd1498Szrj 	--__tmp;
115438fd1498Szrj 	return *__tmp;
115538fd1498Szrj       }
115638fd1498Szrj 
115738fd1498Szrj       // [23.2.2.3] modifiers
115838fd1498Szrj       /**
115938fd1498Szrj        *  @brief  Add data to the front of the %list.
116038fd1498Szrj        *  @param  __x  Data to be added.
116138fd1498Szrj        *
116238fd1498Szrj        *  This is a typical stack operation.  The function creates an
116338fd1498Szrj        *  element at the front of the %list and assigns the given data
116438fd1498Szrj        *  to it.  Due to the nature of a %list this operation can be
116538fd1498Szrj        *  done in constant time, and does not invalidate iterators and
116638fd1498Szrj        *  references.
116738fd1498Szrj        */
116838fd1498Szrj       void
116938fd1498Szrj       push_front(const value_type& __x)
117038fd1498Szrj       { this->_M_insert(begin(), __x); }
117138fd1498Szrj 
117238fd1498Szrj #if __cplusplus >= 201103L
117338fd1498Szrj       void
117438fd1498Szrj       push_front(value_type&& __x)
117538fd1498Szrj       { this->_M_insert(begin(), std::move(__x)); }
117638fd1498Szrj 
117738fd1498Szrj       template<typename... _Args>
117838fd1498Szrj #if __cplusplus > 201402L
117938fd1498Szrj 	reference
118038fd1498Szrj #else
118138fd1498Szrj 	void
118238fd1498Szrj #endif
118338fd1498Szrj 	emplace_front(_Args&&... __args)
118438fd1498Szrj 	{
118538fd1498Szrj 	  this->_M_insert(begin(), std::forward<_Args>(__args)...);
118638fd1498Szrj #if __cplusplus > 201402L
118738fd1498Szrj 	  return front();
118838fd1498Szrj #endif
118938fd1498Szrj 	}
119038fd1498Szrj #endif
119138fd1498Szrj 
119238fd1498Szrj       /**
119338fd1498Szrj        *  @brief  Removes first element.
119438fd1498Szrj        *
119538fd1498Szrj        *  This is a typical stack operation.  It shrinks the %list by
119638fd1498Szrj        *  one.  Due to the nature of a %list this operation can be done
119738fd1498Szrj        *  in constant time, and only invalidates iterators/references to
119838fd1498Szrj        *  the element being removed.
119938fd1498Szrj        *
120038fd1498Szrj        *  Note that no data is returned, and if the first element's data
120138fd1498Szrj        *  is needed, it should be retrieved before pop_front() is
120238fd1498Szrj        *  called.
120338fd1498Szrj        */
120438fd1498Szrj       void
120538fd1498Szrj       pop_front() _GLIBCXX_NOEXCEPT
120638fd1498Szrj       { this->_M_erase(begin()); }
120738fd1498Szrj 
120838fd1498Szrj       /**
120938fd1498Szrj        *  @brief  Add data to the end of the %list.
121038fd1498Szrj        *  @param  __x  Data to be added.
121138fd1498Szrj        *
121238fd1498Szrj        *  This is a typical stack operation.  The function creates an
121338fd1498Szrj        *  element at the end of the %list and assigns the given data to
121438fd1498Szrj        *  it.  Due to the nature of a %list this operation can be done
121538fd1498Szrj        *  in constant time, and does not invalidate iterators and
121638fd1498Szrj        *  references.
121738fd1498Szrj        */
121838fd1498Szrj       void
121938fd1498Szrj       push_back(const value_type& __x)
122038fd1498Szrj       { this->_M_insert(end(), __x); }
122138fd1498Szrj 
122238fd1498Szrj #if __cplusplus >= 201103L
122338fd1498Szrj       void
122438fd1498Szrj       push_back(value_type&& __x)
122538fd1498Szrj       { this->_M_insert(end(), std::move(__x)); }
122638fd1498Szrj 
122738fd1498Szrj       template<typename... _Args>
122838fd1498Szrj #if __cplusplus > 201402L
122938fd1498Szrj 	reference
123038fd1498Szrj #else
123138fd1498Szrj 	void
123238fd1498Szrj #endif
123338fd1498Szrj 	emplace_back(_Args&&... __args)
123438fd1498Szrj 	{
123538fd1498Szrj 	  this->_M_insert(end(), std::forward<_Args>(__args)...);
123638fd1498Szrj #if __cplusplus > 201402L
123738fd1498Szrj 	return back();
123838fd1498Szrj #endif
123938fd1498Szrj 	}
124038fd1498Szrj #endif
124138fd1498Szrj 
124238fd1498Szrj       /**
124338fd1498Szrj        *  @brief  Removes last element.
124438fd1498Szrj        *
124538fd1498Szrj        *  This is a typical stack operation.  It shrinks the %list by
124638fd1498Szrj        *  one.  Due to the nature of a %list this operation can be done
124738fd1498Szrj        *  in constant time, and only invalidates iterators/references to
124838fd1498Szrj        *  the element being removed.
124938fd1498Szrj        *
125038fd1498Szrj        *  Note that no data is returned, and if the last element's data
125138fd1498Szrj        *  is needed, it should be retrieved before pop_back() is called.
125238fd1498Szrj        */
125338fd1498Szrj       void
125438fd1498Szrj       pop_back() _GLIBCXX_NOEXCEPT
125538fd1498Szrj       { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
125638fd1498Szrj 
125738fd1498Szrj #if __cplusplus >= 201103L
125838fd1498Szrj       /**
125938fd1498Szrj        *  @brief  Constructs object in %list before specified iterator.
126038fd1498Szrj        *  @param  __position  A const_iterator into the %list.
126138fd1498Szrj        *  @param  __args  Arguments.
126238fd1498Szrj        *  @return  An iterator that points to the inserted data.
126338fd1498Szrj        *
126438fd1498Szrj        *  This function will insert an object of type T constructed
126538fd1498Szrj        *  with T(std::forward<Args>(args)...) before the specified
126638fd1498Szrj        *  location.  Due to the nature of a %list this operation can
126738fd1498Szrj        *  be done in constant time, and does not invalidate iterators
126838fd1498Szrj        *  and references.
126938fd1498Szrj        */
127038fd1498Szrj       template<typename... _Args>
127138fd1498Szrj 	iterator
127238fd1498Szrj 	emplace(const_iterator __position, _Args&&... __args);
127338fd1498Szrj 
127438fd1498Szrj       /**
127538fd1498Szrj        *  @brief  Inserts given value into %list before specified iterator.
127638fd1498Szrj        *  @param  __position  A const_iterator into the %list.
127738fd1498Szrj        *  @param  __x  Data to be inserted.
127838fd1498Szrj        *  @return  An iterator that points to the inserted data.
127938fd1498Szrj        *
128038fd1498Szrj        *  This function will insert a copy of the given value before
128138fd1498Szrj        *  the specified location.  Due to the nature of a %list this
128238fd1498Szrj        *  operation can be done in constant time, and does not
128338fd1498Szrj        *  invalidate iterators and references.
128438fd1498Szrj        */
128538fd1498Szrj       iterator
128638fd1498Szrj       insert(const_iterator __position, const value_type& __x);
128738fd1498Szrj #else
128838fd1498Szrj       /**
128938fd1498Szrj        *  @brief  Inserts given value into %list before specified iterator.
129038fd1498Szrj        *  @param  __position  An iterator into the %list.
129138fd1498Szrj        *  @param  __x  Data to be inserted.
129238fd1498Szrj        *  @return  An iterator that points to the inserted data.
129338fd1498Szrj        *
129438fd1498Szrj        *  This function will insert a copy of the given value before
129538fd1498Szrj        *  the specified location.  Due to the nature of a %list this
129638fd1498Szrj        *  operation can be done in constant time, and does not
129738fd1498Szrj        *  invalidate iterators and references.
129838fd1498Szrj        */
129938fd1498Szrj       iterator
130038fd1498Szrj       insert(iterator __position, const value_type& __x);
130138fd1498Szrj #endif
130238fd1498Szrj 
130338fd1498Szrj #if __cplusplus >= 201103L
130438fd1498Szrj       /**
130538fd1498Szrj        *  @brief  Inserts given rvalue into %list before specified iterator.
130638fd1498Szrj        *  @param  __position  A const_iterator into the %list.
130738fd1498Szrj        *  @param  __x  Data to be inserted.
130838fd1498Szrj        *  @return  An iterator that points to the inserted data.
130938fd1498Szrj        *
131038fd1498Szrj        *  This function will insert a copy of the given rvalue before
131138fd1498Szrj        *  the specified location.  Due to the nature of a %list this
131238fd1498Szrj        *  operation can be done in constant time, and does not
131338fd1498Szrj        *  invalidate iterators and references.
131438fd1498Szrj 	*/
131538fd1498Szrj       iterator
131638fd1498Szrj       insert(const_iterator __position, value_type&& __x)
131738fd1498Szrj       { return emplace(__position, std::move(__x)); }
131838fd1498Szrj 
131938fd1498Szrj       /**
132038fd1498Szrj        *  @brief  Inserts the contents of an initializer_list into %list
132138fd1498Szrj        *          before specified const_iterator.
132238fd1498Szrj        *  @param  __p  A const_iterator into the %list.
132338fd1498Szrj        *  @param  __l  An initializer_list of value_type.
132438fd1498Szrj        *  @return  An iterator pointing to the first element inserted
132538fd1498Szrj        *           (or __position).
132638fd1498Szrj        *
132738fd1498Szrj        *  This function will insert copies of the data in the
132838fd1498Szrj        *  initializer_list @a l into the %list before the location
132938fd1498Szrj        *  specified by @a p.
133038fd1498Szrj        *
133138fd1498Szrj        *  This operation is linear in the number of elements inserted and
133238fd1498Szrj        *  does not invalidate iterators and references.
133338fd1498Szrj        */
133438fd1498Szrj       iterator
133538fd1498Szrj       insert(const_iterator __p, initializer_list<value_type> __l)
133638fd1498Szrj       { return this->insert(__p, __l.begin(), __l.end()); }
133738fd1498Szrj #endif
133838fd1498Szrj 
133938fd1498Szrj #if __cplusplus >= 201103L
134038fd1498Szrj       /**
134138fd1498Szrj        *  @brief  Inserts a number of copies of given data into the %list.
134238fd1498Szrj        *  @param  __position  A const_iterator into the %list.
134338fd1498Szrj        *  @param  __n  Number of elements to be inserted.
134438fd1498Szrj        *  @param  __x  Data to be inserted.
134538fd1498Szrj        *  @return  An iterator pointing to the first element inserted
134638fd1498Szrj        *           (or __position).
134738fd1498Szrj        *
134838fd1498Szrj        *  This function will insert a specified number of copies of the
134938fd1498Szrj        *  given data before the location specified by @a position.
135038fd1498Szrj        *
135138fd1498Szrj        *  This operation is linear in the number of elements inserted and
135238fd1498Szrj        *  does not invalidate iterators and references.
135338fd1498Szrj        */
135438fd1498Szrj       iterator
135538fd1498Szrj       insert(const_iterator __position, size_type __n, const value_type& __x);
135638fd1498Szrj #else
135738fd1498Szrj       /**
135838fd1498Szrj        *  @brief  Inserts a number of copies of given data into the %list.
135938fd1498Szrj        *  @param  __position  An iterator into the %list.
136038fd1498Szrj        *  @param  __n  Number of elements to be inserted.
136138fd1498Szrj        *  @param  __x  Data to be inserted.
136238fd1498Szrj        *
136338fd1498Szrj        *  This function will insert a specified number of copies of the
136438fd1498Szrj        *  given data before the location specified by @a position.
136538fd1498Szrj        *
136638fd1498Szrj        *  This operation is linear in the number of elements inserted and
136738fd1498Szrj        *  does not invalidate iterators and references.
136838fd1498Szrj        */
136938fd1498Szrj       void
137038fd1498Szrj       insert(iterator __position, size_type __n, const value_type& __x)
137138fd1498Szrj       {
137238fd1498Szrj 	list __tmp(__n, __x, get_allocator());
137338fd1498Szrj 	splice(__position, __tmp);
137438fd1498Szrj       }
137538fd1498Szrj #endif
137638fd1498Szrj 
137738fd1498Szrj #if __cplusplus >= 201103L
137838fd1498Szrj       /**
137938fd1498Szrj        *  @brief  Inserts a range into the %list.
138038fd1498Szrj        *  @param  __position  A const_iterator into the %list.
138138fd1498Szrj        *  @param  __first  An input iterator.
138238fd1498Szrj        *  @param  __last   An input iterator.
138338fd1498Szrj        *  @return  An iterator pointing to the first element inserted
138438fd1498Szrj        *           (or __position).
138538fd1498Szrj        *
138638fd1498Szrj        *  This function will insert copies of the data in the range [@a
138738fd1498Szrj        *  first,@a last) into the %list before the location specified by
138838fd1498Szrj        *  @a position.
138938fd1498Szrj        *
139038fd1498Szrj        *  This operation is linear in the number of elements inserted and
139138fd1498Szrj        *  does not invalidate iterators and references.
139238fd1498Szrj        */
139338fd1498Szrj       template<typename _InputIterator,
139438fd1498Szrj 	       typename = std::_RequireInputIter<_InputIterator>>
139538fd1498Szrj 	iterator
139638fd1498Szrj 	insert(const_iterator __position, _InputIterator __first,
139738fd1498Szrj 	       _InputIterator __last);
139838fd1498Szrj #else
139938fd1498Szrj       /**
140038fd1498Szrj        *  @brief  Inserts a range into the %list.
140138fd1498Szrj        *  @param  __position  An iterator into the %list.
140238fd1498Szrj        *  @param  __first  An input iterator.
140338fd1498Szrj        *  @param  __last   An input iterator.
140438fd1498Szrj        *
140538fd1498Szrj        *  This function will insert copies of the data in the range [@a
140638fd1498Szrj        *  first,@a last) into the %list before the location specified by
140738fd1498Szrj        *  @a position.
140838fd1498Szrj        *
140938fd1498Szrj        *  This operation is linear in the number of elements inserted and
141038fd1498Szrj        *  does not invalidate iterators and references.
141138fd1498Szrj        */
141238fd1498Szrj       template<typename _InputIterator>
141338fd1498Szrj 	void
141438fd1498Szrj 	insert(iterator __position, _InputIterator __first,
141538fd1498Szrj 	       _InputIterator __last)
141638fd1498Szrj 	{
141738fd1498Szrj 	  list __tmp(__first, __last, get_allocator());
141838fd1498Szrj 	  splice(__position, __tmp);
141938fd1498Szrj 	}
142038fd1498Szrj #endif
142138fd1498Szrj 
142238fd1498Szrj       /**
142338fd1498Szrj        *  @brief  Remove element at given position.
142438fd1498Szrj        *  @param  __position  Iterator pointing to element to be erased.
142538fd1498Szrj        *  @return  An iterator pointing to the next element (or end()).
142638fd1498Szrj        *
142738fd1498Szrj        *  This function will erase the element at the given position and thus
142838fd1498Szrj        *  shorten the %list by one.
142938fd1498Szrj        *
143038fd1498Szrj        *  Due to the nature of a %list this operation can be done in
143138fd1498Szrj        *  constant time, and only invalidates iterators/references to
143238fd1498Szrj        *  the element being removed.  The user is also cautioned that
143338fd1498Szrj        *  this function only erases the element, and that if the element
143438fd1498Szrj        *  is itself a pointer, the pointed-to memory is not touched in
143538fd1498Szrj        *  any way.  Managing the pointer is the user's responsibility.
143638fd1498Szrj        */
143738fd1498Szrj       iterator
143838fd1498Szrj #if __cplusplus >= 201103L
143938fd1498Szrj       erase(const_iterator __position) noexcept;
144038fd1498Szrj #else
144138fd1498Szrj       erase(iterator __position);
144238fd1498Szrj #endif
144338fd1498Szrj 
144438fd1498Szrj       /**
144538fd1498Szrj        *  @brief  Remove a range of elements.
144638fd1498Szrj        *  @param  __first  Iterator pointing to the first element to be erased.
144738fd1498Szrj        *  @param  __last  Iterator pointing to one past the last element to be
144838fd1498Szrj        *                erased.
144938fd1498Szrj        *  @return  An iterator pointing to the element pointed to by @a last
145038fd1498Szrj        *           prior to erasing (or end()).
145138fd1498Szrj        *
145238fd1498Szrj        *  This function will erase the elements in the range @a
145338fd1498Szrj        *  [first,last) and shorten the %list accordingly.
145438fd1498Szrj        *
145538fd1498Szrj        *  This operation is linear time in the size of the range and only
145638fd1498Szrj        *  invalidates iterators/references to the element being removed.
145738fd1498Szrj        *  The user is also cautioned that this function only erases the
145838fd1498Szrj        *  elements, and that if the elements themselves are pointers, the
145938fd1498Szrj        *  pointed-to memory is not touched in any way.  Managing the pointer
146038fd1498Szrj        *  is the user's responsibility.
146138fd1498Szrj        */
146238fd1498Szrj       iterator
146338fd1498Szrj #if __cplusplus >= 201103L
146438fd1498Szrj       erase(const_iterator __first, const_iterator __last) noexcept
146538fd1498Szrj #else
146638fd1498Szrj       erase(iterator __first, iterator __last)
146738fd1498Szrj #endif
146838fd1498Szrj       {
146938fd1498Szrj 	while (__first != __last)
147038fd1498Szrj 	  __first = erase(__first);
147138fd1498Szrj 	return __last._M_const_cast();
147238fd1498Szrj       }
147338fd1498Szrj 
147438fd1498Szrj       /**
147538fd1498Szrj        *  @brief  Swaps data with another %list.
147638fd1498Szrj        *  @param  __x  A %list of the same element and allocator types.
147738fd1498Szrj        *
147838fd1498Szrj        *  This exchanges the elements between two lists in constant
147938fd1498Szrj        *  time.  Note that the global std::swap() function is
148038fd1498Szrj        *  specialized such that std::swap(l1,l2) will feed to this
148138fd1498Szrj        *  function.
148238fd1498Szrj        *
148338fd1498Szrj        *  Whether the allocators are swapped depends on the allocator traits.
148438fd1498Szrj        */
148538fd1498Szrj       void
148638fd1498Szrj       swap(list& __x) _GLIBCXX_NOEXCEPT
148738fd1498Szrj       {
148838fd1498Szrj 	__detail::_List_node_base::swap(this->_M_impl._M_node,
148938fd1498Szrj 					__x._M_impl._M_node);
149038fd1498Szrj 
149138fd1498Szrj 	size_t __xsize = __x._M_get_size();
149238fd1498Szrj 	__x._M_set_size(this->_M_get_size());
149338fd1498Szrj 	this->_M_set_size(__xsize);
149438fd1498Szrj 
149538fd1498Szrj 	_Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
149638fd1498Szrj 				       __x._M_get_Node_allocator());
149738fd1498Szrj       }
149838fd1498Szrj 
149938fd1498Szrj       /**
150038fd1498Szrj        *  Erases all the elements.  Note that this function only erases
150138fd1498Szrj        *  the elements, and that if the elements themselves are
150238fd1498Szrj        *  pointers, the pointed-to memory is not touched in any way.
150338fd1498Szrj        *  Managing the pointer is the user's responsibility.
150438fd1498Szrj        */
150538fd1498Szrj       void
150638fd1498Szrj       clear() _GLIBCXX_NOEXCEPT
150738fd1498Szrj       {
150838fd1498Szrj 	_Base::_M_clear();
150938fd1498Szrj 	_Base::_M_init();
151038fd1498Szrj       }
151138fd1498Szrj 
151238fd1498Szrj       // [23.2.2.4] list operations
151338fd1498Szrj       /**
151438fd1498Szrj        *  @brief  Insert contents of another %list.
151538fd1498Szrj        *  @param  __position  Iterator referencing the element to insert before.
151638fd1498Szrj        *  @param  __x  Source list.
151738fd1498Szrj        *
151838fd1498Szrj        *  The elements of @a __x are inserted in constant time in front of
151938fd1498Szrj        *  the element referenced by @a __position.  @a __x becomes an empty
152038fd1498Szrj        *  list.
152138fd1498Szrj        *
152238fd1498Szrj        *  Requires this != @a __x.
152338fd1498Szrj        */
152438fd1498Szrj       void
152538fd1498Szrj #if __cplusplus >= 201103L
152638fd1498Szrj       splice(const_iterator __position, list&& __x) noexcept
152738fd1498Szrj #else
152838fd1498Szrj       splice(iterator __position, list& __x)
152938fd1498Szrj #endif
153038fd1498Szrj       {
153138fd1498Szrj 	if (!__x.empty())
153238fd1498Szrj 	  {
153338fd1498Szrj 	    _M_check_equal_allocators(__x);
153438fd1498Szrj 
153538fd1498Szrj 	    this->_M_transfer(__position._M_const_cast(),
153638fd1498Szrj 			      __x.begin(), __x.end());
153738fd1498Szrj 
153838fd1498Szrj 	    this->_M_inc_size(__x._M_get_size());
153938fd1498Szrj 	    __x._M_set_size(0);
154038fd1498Szrj 	  }
154138fd1498Szrj       }
154238fd1498Szrj 
154338fd1498Szrj #if __cplusplus >= 201103L
154438fd1498Szrj       void
154538fd1498Szrj       splice(const_iterator __position, list& __x) noexcept
154638fd1498Szrj       { splice(__position, std::move(__x)); }
154738fd1498Szrj #endif
154838fd1498Szrj 
154938fd1498Szrj #if __cplusplus >= 201103L
155038fd1498Szrj       /**
155138fd1498Szrj        *  @brief  Insert element from another %list.
155238fd1498Szrj        *  @param  __position  Const_iterator referencing the element to
155338fd1498Szrj        *                      insert before.
155438fd1498Szrj        *  @param  __x  Source list.
155538fd1498Szrj        *  @param  __i  Const_iterator referencing the element to move.
155638fd1498Szrj        *
155738fd1498Szrj        *  Removes the element in list @a __x referenced by @a __i and
155838fd1498Szrj        *  inserts it into the current list before @a __position.
155938fd1498Szrj        */
156038fd1498Szrj       void
156138fd1498Szrj       splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
156238fd1498Szrj #else
156338fd1498Szrj       /**
156438fd1498Szrj        *  @brief  Insert element from another %list.
156538fd1498Szrj        *  @param  __position  Iterator referencing the element to insert before.
156638fd1498Szrj        *  @param  __x  Source list.
156738fd1498Szrj        *  @param  __i  Iterator referencing the element to move.
156838fd1498Szrj        *
156938fd1498Szrj        *  Removes the element in list @a __x referenced by @a __i and
157038fd1498Szrj        *  inserts it into the current list before @a __position.
157138fd1498Szrj        */
157238fd1498Szrj       void
157338fd1498Szrj       splice(iterator __position, list& __x, iterator __i)
157438fd1498Szrj #endif
157538fd1498Szrj       {
157638fd1498Szrj 	iterator __j = __i._M_const_cast();
157738fd1498Szrj 	++__j;
157838fd1498Szrj 	if (__position == __i || __position == __j)
157938fd1498Szrj 	  return;
158038fd1498Szrj 
158138fd1498Szrj 	if (this != std::__addressof(__x))
158238fd1498Szrj 	  _M_check_equal_allocators(__x);
158338fd1498Szrj 
158438fd1498Szrj 	this->_M_transfer(__position._M_const_cast(),
158538fd1498Szrj 			  __i._M_const_cast(), __j);
158638fd1498Szrj 
158738fd1498Szrj 	this->_M_inc_size(1);
158838fd1498Szrj 	__x._M_dec_size(1);
158938fd1498Szrj       }
159038fd1498Szrj 
159138fd1498Szrj #if __cplusplus >= 201103L
159238fd1498Szrj       /**
159338fd1498Szrj        *  @brief  Insert element from another %list.
159438fd1498Szrj        *  @param  __position  Const_iterator referencing the element to
159538fd1498Szrj        *                      insert before.
159638fd1498Szrj        *  @param  __x  Source list.
159738fd1498Szrj        *  @param  __i  Const_iterator referencing the element to move.
159838fd1498Szrj        *
159938fd1498Szrj        *  Removes the element in list @a __x referenced by @a __i and
160038fd1498Szrj        *  inserts it into the current list before @a __position.
160138fd1498Szrj        */
160238fd1498Szrj       void
160338fd1498Szrj       splice(const_iterator __position, list& __x, const_iterator __i) noexcept
160438fd1498Szrj       { splice(__position, std::move(__x), __i); }
160538fd1498Szrj #endif
160638fd1498Szrj 
160738fd1498Szrj #if __cplusplus >= 201103L
160838fd1498Szrj       /**
160938fd1498Szrj        *  @brief  Insert range from another %list.
161038fd1498Szrj        *  @param  __position  Const_iterator referencing the element to
161138fd1498Szrj        *                      insert before.
161238fd1498Szrj        *  @param  __x  Source list.
161338fd1498Szrj        *  @param  __first  Const_iterator referencing the start of range in x.
161438fd1498Szrj        *  @param  __last  Const_iterator referencing the end of range in x.
161538fd1498Szrj        *
161638fd1498Szrj        *  Removes elements in the range [__first,__last) and inserts them
161738fd1498Szrj        *  before @a __position in constant time.
161838fd1498Szrj        *
161938fd1498Szrj        *  Undefined if @a __position is in [__first,__last).
162038fd1498Szrj        */
162138fd1498Szrj       void
162238fd1498Szrj       splice(const_iterator __position, list&& __x, const_iterator __first,
162338fd1498Szrj 	     const_iterator __last) noexcept
162438fd1498Szrj #else
162538fd1498Szrj       /**
162638fd1498Szrj        *  @brief  Insert range from another %list.
162738fd1498Szrj        *  @param  __position  Iterator referencing the element to insert before.
162838fd1498Szrj        *  @param  __x  Source list.
162938fd1498Szrj        *  @param  __first  Iterator referencing the start of range in x.
163038fd1498Szrj        *  @param  __last  Iterator referencing the end of range in x.
163138fd1498Szrj        *
163238fd1498Szrj        *  Removes elements in the range [__first,__last) and inserts them
163338fd1498Szrj        *  before @a __position in constant time.
163438fd1498Szrj        *
163538fd1498Szrj        *  Undefined if @a __position is in [__first,__last).
163638fd1498Szrj        */
163738fd1498Szrj       void
163838fd1498Szrj       splice(iterator __position, list& __x, iterator __first,
163938fd1498Szrj 	     iterator __last)
164038fd1498Szrj #endif
164138fd1498Szrj       {
164238fd1498Szrj 	if (__first != __last)
164338fd1498Szrj 	  {
164438fd1498Szrj 	    if (this != std::__addressof(__x))
164538fd1498Szrj 	      _M_check_equal_allocators(__x);
164638fd1498Szrj 
164738fd1498Szrj 	    size_t __n = _S_distance(__first, __last);
164838fd1498Szrj 	    this->_M_inc_size(__n);
164938fd1498Szrj 	    __x._M_dec_size(__n);
165038fd1498Szrj 
165138fd1498Szrj 	    this->_M_transfer(__position._M_const_cast(),
165238fd1498Szrj 			      __first._M_const_cast(),
165338fd1498Szrj 			      __last._M_const_cast());
165438fd1498Szrj 	  }
165538fd1498Szrj       }
165638fd1498Szrj 
165738fd1498Szrj #if __cplusplus >= 201103L
165838fd1498Szrj       /**
165938fd1498Szrj        *  @brief  Insert range from another %list.
166038fd1498Szrj        *  @param  __position  Const_iterator referencing the element to
166138fd1498Szrj        *                      insert before.
166238fd1498Szrj        *  @param  __x  Source list.
166338fd1498Szrj        *  @param  __first  Const_iterator referencing the start of range in x.
166438fd1498Szrj        *  @param  __last  Const_iterator referencing the end of range in x.
166538fd1498Szrj        *
166638fd1498Szrj        *  Removes elements in the range [__first,__last) and inserts them
166738fd1498Szrj        *  before @a __position in constant time.
166838fd1498Szrj        *
166938fd1498Szrj        *  Undefined if @a __position is in [__first,__last).
167038fd1498Szrj        */
167138fd1498Szrj       void
167238fd1498Szrj       splice(const_iterator __position, list& __x, const_iterator __first,
167338fd1498Szrj 	     const_iterator __last) noexcept
167438fd1498Szrj       { splice(__position, std::move(__x), __first, __last); }
167538fd1498Szrj #endif
167638fd1498Szrj 
167738fd1498Szrj       /**
167838fd1498Szrj        *  @brief  Remove all elements equal to value.
167938fd1498Szrj        *  @param  __value  The value to remove.
168038fd1498Szrj        *
168138fd1498Szrj        *  Removes every element in the list equal to @a value.
168238fd1498Szrj        *  Remaining elements stay in list order.  Note that this
168338fd1498Szrj        *  function only erases the elements, and that if the elements
168438fd1498Szrj        *  themselves are pointers, the pointed-to memory is not
168538fd1498Szrj        *  touched in any way.  Managing the pointer is the user's
168638fd1498Szrj        *  responsibility.
168738fd1498Szrj        */
168838fd1498Szrj       void
168938fd1498Szrj       remove(const _Tp& __value);
169038fd1498Szrj 
169138fd1498Szrj       /**
169238fd1498Szrj        *  @brief  Remove all elements satisfying a predicate.
169338fd1498Szrj        *  @tparam  _Predicate  Unary predicate function or object.
169438fd1498Szrj        *
169538fd1498Szrj        *  Removes every element in the list for which the predicate
169638fd1498Szrj        *  returns true.  Remaining elements stay in list order.  Note
169738fd1498Szrj        *  that this function only erases the elements, and that if the
169838fd1498Szrj        *  elements themselves are pointers, the pointed-to memory is
169938fd1498Szrj        *  not touched in any way.  Managing the pointer is the user's
170038fd1498Szrj        *  responsibility.
170138fd1498Szrj        */
170238fd1498Szrj       template<typename _Predicate>
170338fd1498Szrj 	void
170438fd1498Szrj 	remove_if(_Predicate);
170538fd1498Szrj 
170638fd1498Szrj       /**
170738fd1498Szrj        *  @brief  Remove consecutive duplicate elements.
170838fd1498Szrj        *
170938fd1498Szrj        *  For each consecutive set of elements with the same value,
171038fd1498Szrj        *  remove all but the first one.  Remaining elements stay in
171138fd1498Szrj        *  list order.  Note that this function only erases the
171238fd1498Szrj        *  elements, and that if the elements themselves are pointers,
171338fd1498Szrj        *  the pointed-to memory is not touched in any way.  Managing
171438fd1498Szrj        *  the pointer is the user's responsibility.
171538fd1498Szrj        */
171638fd1498Szrj       void
171738fd1498Szrj       unique();
171838fd1498Szrj 
171938fd1498Szrj       /**
172038fd1498Szrj        *  @brief  Remove consecutive elements satisfying a predicate.
172138fd1498Szrj        *  @tparam _BinaryPredicate  Binary predicate function or object.
172238fd1498Szrj        *
172338fd1498Szrj        *  For each consecutive set of elements [first,last) that
172438fd1498Szrj        *  satisfy predicate(first,i) where i is an iterator in
172538fd1498Szrj        *  [first,last), remove all but the first one.  Remaining
172638fd1498Szrj        *  elements stay in list order.  Note that this function only
172738fd1498Szrj        *  erases the elements, and that if the elements themselves are
172838fd1498Szrj        *  pointers, the pointed-to memory is not touched in any way.
172938fd1498Szrj        *  Managing the pointer is the user's responsibility.
173038fd1498Szrj        */
173138fd1498Szrj       template<typename _BinaryPredicate>
173238fd1498Szrj 	void
173338fd1498Szrj 	unique(_BinaryPredicate);
173438fd1498Szrj 
173538fd1498Szrj       /**
173638fd1498Szrj        *  @brief  Merge sorted lists.
173738fd1498Szrj        *  @param  __x  Sorted list to merge.
173838fd1498Szrj        *
173938fd1498Szrj        *  Assumes that both @a __x and this list are sorted according to
174038fd1498Szrj        *  operator<().  Merges elements of @a __x into this list in
174138fd1498Szrj        *  sorted order, leaving @a __x empty when complete.  Elements in
174238fd1498Szrj        *  this list precede elements in @a __x that are equal.
174338fd1498Szrj        */
174438fd1498Szrj #if __cplusplus >= 201103L
174538fd1498Szrj       void
174638fd1498Szrj       merge(list&& __x);
174738fd1498Szrj 
174838fd1498Szrj       void
174938fd1498Szrj       merge(list& __x)
175038fd1498Szrj       { merge(std::move(__x)); }
175138fd1498Szrj #else
175238fd1498Szrj       void
175338fd1498Szrj       merge(list& __x);
175438fd1498Szrj #endif
175538fd1498Szrj 
175638fd1498Szrj       /**
175738fd1498Szrj        *  @brief  Merge sorted lists according to comparison function.
175838fd1498Szrj        *  @tparam _StrictWeakOrdering Comparison function defining
175938fd1498Szrj        *  sort order.
176038fd1498Szrj        *  @param  __x  Sorted list to merge.
176138fd1498Szrj        *  @param  __comp  Comparison functor.
176238fd1498Szrj        *
176338fd1498Szrj        *  Assumes that both @a __x and this list are sorted according to
176438fd1498Szrj        *  StrictWeakOrdering.  Merges elements of @a __x into this list
176538fd1498Szrj        *  in sorted order, leaving @a __x empty when complete.  Elements
176638fd1498Szrj        *  in this list precede elements in @a __x that are equivalent
176738fd1498Szrj        *  according to StrictWeakOrdering().
176838fd1498Szrj        */
176938fd1498Szrj #if __cplusplus >= 201103L
177038fd1498Szrj       template<typename _StrictWeakOrdering>
177138fd1498Szrj 	void
177238fd1498Szrj 	merge(list&& __x, _StrictWeakOrdering __comp);
177338fd1498Szrj 
177438fd1498Szrj       template<typename _StrictWeakOrdering>
177538fd1498Szrj 	void
177638fd1498Szrj 	merge(list& __x, _StrictWeakOrdering __comp)
177738fd1498Szrj 	{ merge(std::move(__x), __comp); }
177838fd1498Szrj #else
177938fd1498Szrj       template<typename _StrictWeakOrdering>
178038fd1498Szrj 	void
178138fd1498Szrj 	merge(list& __x, _StrictWeakOrdering __comp);
178238fd1498Szrj #endif
178338fd1498Szrj 
178438fd1498Szrj       /**
178538fd1498Szrj        *  @brief  Reverse the elements in list.
178638fd1498Szrj        *
178738fd1498Szrj        *  Reverse the order of elements in the list in linear time.
178838fd1498Szrj        */
178938fd1498Szrj       void
179038fd1498Szrj       reverse() _GLIBCXX_NOEXCEPT
179138fd1498Szrj       { this->_M_impl._M_node._M_reverse(); }
179238fd1498Szrj 
179338fd1498Szrj       /**
179438fd1498Szrj        *  @brief  Sort the elements.
179538fd1498Szrj        *
179638fd1498Szrj        *  Sorts the elements of this list in NlogN time.  Equivalent
179738fd1498Szrj        *  elements remain in list order.
179838fd1498Szrj        */
179938fd1498Szrj       void
180038fd1498Szrj       sort();
180138fd1498Szrj 
180238fd1498Szrj       /**
180338fd1498Szrj        *  @brief  Sort the elements according to comparison function.
180438fd1498Szrj        *
180538fd1498Szrj        *  Sorts the elements of this list in NlogN time.  Equivalent
180638fd1498Szrj        *  elements remain in list order.
180738fd1498Szrj        */
180838fd1498Szrj       template<typename _StrictWeakOrdering>
180938fd1498Szrj 	void
181038fd1498Szrj 	sort(_StrictWeakOrdering);
181138fd1498Szrj 
181238fd1498Szrj     protected:
181338fd1498Szrj       // Internal constructor functions follow.
181438fd1498Szrj 
181538fd1498Szrj       // Called by the range constructor to implement [23.1.1]/9
181638fd1498Szrj 
181738fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
181838fd1498Szrj       // 438. Ambiguity in the "do the right thing" clause
181938fd1498Szrj       template<typename _Integer>
182038fd1498Szrj 	void
182138fd1498Szrj 	_M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
182238fd1498Szrj 	{ _M_fill_initialize(static_cast<size_type>(__n), __x); }
182338fd1498Szrj 
182438fd1498Szrj       // Called by the range constructor to implement [23.1.1]/9
182538fd1498Szrj       template<typename _InputIterator>
182638fd1498Szrj 	void
182738fd1498Szrj 	_M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
182838fd1498Szrj 			       __false_type)
182938fd1498Szrj 	{
183038fd1498Szrj 	  for (; __first != __last; ++__first)
183138fd1498Szrj #if __cplusplus >= 201103L
183238fd1498Szrj 	    emplace_back(*__first);
183338fd1498Szrj #else
183438fd1498Szrj 	    push_back(*__first);
183538fd1498Szrj #endif
183638fd1498Szrj 	}
183738fd1498Szrj 
183838fd1498Szrj       // Called by list(n,v,a), and the range constructor when it turns out
183938fd1498Szrj       // to be the same thing.
184038fd1498Szrj       void
184138fd1498Szrj       _M_fill_initialize(size_type __n, const value_type& __x)
184238fd1498Szrj       {
184338fd1498Szrj 	for (; __n; --__n)
184438fd1498Szrj 	  push_back(__x);
184538fd1498Szrj       }
184638fd1498Szrj 
184738fd1498Szrj #if __cplusplus >= 201103L
184838fd1498Szrj       // Called by list(n).
184938fd1498Szrj       void
185038fd1498Szrj       _M_default_initialize(size_type __n)
185138fd1498Szrj       {
185238fd1498Szrj 	for (; __n; --__n)
185338fd1498Szrj 	  emplace_back();
185438fd1498Szrj       }
185538fd1498Szrj 
185638fd1498Szrj       // Called by resize(sz).
185738fd1498Szrj       void
185838fd1498Szrj       _M_default_append(size_type __n);
185938fd1498Szrj #endif
186038fd1498Szrj 
186138fd1498Szrj       // Internal assign functions follow.
186238fd1498Szrj 
186338fd1498Szrj       // Called by the range assign to implement [23.1.1]/9
186438fd1498Szrj 
186538fd1498Szrj       // _GLIBCXX_RESOLVE_LIB_DEFECTS
186638fd1498Szrj       // 438. Ambiguity in the "do the right thing" clause
186738fd1498Szrj       template<typename _Integer>
186838fd1498Szrj 	void
186938fd1498Szrj 	_M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
187038fd1498Szrj 	{ _M_fill_assign(__n, __val); }
187138fd1498Szrj 
187238fd1498Szrj       // Called by the range assign to implement [23.1.1]/9
187338fd1498Szrj       template<typename _InputIterator>
187438fd1498Szrj 	void
187538fd1498Szrj 	_M_assign_dispatch(_InputIterator __first, _InputIterator __last,
187638fd1498Szrj 			   __false_type);
187738fd1498Szrj 
187838fd1498Szrj       // Called by assign(n,t), and the range assign when it turns out
187938fd1498Szrj       // to be the same thing.
188038fd1498Szrj       void
188138fd1498Szrj       _M_fill_assign(size_type __n, const value_type& __val);
188238fd1498Szrj 
188338fd1498Szrj 
188438fd1498Szrj       // Moves the elements from [first,last) before position.
188538fd1498Szrj       void
188638fd1498Szrj       _M_transfer(iterator __position, iterator __first, iterator __last)
188738fd1498Szrj       { __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
188838fd1498Szrj 
188938fd1498Szrj       // Inserts new element at position given and with value given.
189038fd1498Szrj #if __cplusplus < 201103L
189138fd1498Szrj       void
189238fd1498Szrj       _M_insert(iterator __position, const value_type& __x)
189338fd1498Szrj       {
189438fd1498Szrj 	_Node* __tmp = _M_create_node(__x);
189538fd1498Szrj 	__tmp->_M_hook(__position._M_node);
189638fd1498Szrj 	this->_M_inc_size(1);
189738fd1498Szrj       }
189838fd1498Szrj #else
189938fd1498Szrj      template<typename... _Args>
190038fd1498Szrj        void
190138fd1498Szrj        _M_insert(iterator __position, _Args&&... __args)
190238fd1498Szrj        {
190338fd1498Szrj 	 _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
190438fd1498Szrj 	 __tmp->_M_hook(__position._M_node);
190538fd1498Szrj 	 this->_M_inc_size(1);
190638fd1498Szrj        }
190738fd1498Szrj #endif
190838fd1498Szrj 
190938fd1498Szrj       // Erases element at position given.
191038fd1498Szrj       void
191138fd1498Szrj       _M_erase(iterator __position) _GLIBCXX_NOEXCEPT
191238fd1498Szrj       {
191338fd1498Szrj 	this->_M_dec_size(1);
191438fd1498Szrj 	__position._M_node->_M_unhook();
191538fd1498Szrj 	_Node* __n = static_cast<_Node*>(__position._M_node);
191638fd1498Szrj #if __cplusplus >= 201103L
191738fd1498Szrj 	_Node_alloc_traits::destroy(_M_get_Node_allocator(), __n->_M_valptr());
191838fd1498Szrj #else
191938fd1498Szrj 	_Tp_alloc_type(_M_get_Node_allocator()).destroy(__n->_M_valptr());
192038fd1498Szrj #endif
192138fd1498Szrj 
192238fd1498Szrj 	_M_put_node(__n);
192338fd1498Szrj       }
192438fd1498Szrj 
192538fd1498Szrj       // To implement the splice (and merge) bits of N1599.
192638fd1498Szrj       void
192738fd1498Szrj       _M_check_equal_allocators(list& __x) _GLIBCXX_NOEXCEPT
192838fd1498Szrj       {
192938fd1498Szrj 	if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
193038fd1498Szrj 	    _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
193138fd1498Szrj 	  __builtin_abort();
193238fd1498Szrj       }
193338fd1498Szrj 
193438fd1498Szrj       // Used to implement resize.
193538fd1498Szrj       const_iterator
193638fd1498Szrj       _M_resize_pos(size_type& __new_size) const;
193738fd1498Szrj 
193838fd1498Szrj #if __cplusplus >= 201103L
193938fd1498Szrj       void
194038fd1498Szrj       _M_move_assign(list&& __x, true_type) noexcept
194138fd1498Szrj       {
194238fd1498Szrj 	this->_M_clear();
194338fd1498Szrj 	this->_M_move_nodes(std::move(__x));
194438fd1498Szrj 	std::__alloc_on_move(this->_M_get_Node_allocator(),
194538fd1498Szrj 			     __x._M_get_Node_allocator());
194638fd1498Szrj       }
194738fd1498Szrj 
194838fd1498Szrj       void
194938fd1498Szrj       _M_move_assign(list&& __x, false_type)
195038fd1498Szrj       {
195138fd1498Szrj 	if (__x._M_get_Node_allocator() == this->_M_get_Node_allocator())
195238fd1498Szrj 	  _M_move_assign(std::move(__x), true_type{});
195338fd1498Szrj 	else
195438fd1498Szrj 	  // The rvalue's allocator cannot be moved, or is not equal,
195538fd1498Szrj 	  // so we need to individually move each element.
195638fd1498Szrj 	  _M_assign_dispatch(std::__make_move_if_noexcept_iterator(__x.begin()),
195738fd1498Szrj 			     std::__make_move_if_noexcept_iterator(__x.end()),
195838fd1498Szrj 			     __false_type{});
195938fd1498Szrj       }
196038fd1498Szrj #endif
196138fd1498Szrj     };
196238fd1498Szrj 
196338fd1498Szrj #if __cpp_deduction_guides >= 201606
196438fd1498Szrj   template<typename _InputIterator, typename _ValT
196538fd1498Szrj 	     = typename iterator_traits<_InputIterator>::value_type,
196638fd1498Szrj 	   typename _Allocator = allocator<_ValT>,
196738fd1498Szrj 	   typename = _RequireInputIter<_InputIterator>,
196838fd1498Szrj 	   typename = _RequireAllocator<_Allocator>>
196938fd1498Szrj     list(_InputIterator, _InputIterator, _Allocator = _Allocator())
197038fd1498Szrj       -> list<_ValT, _Allocator>;
197138fd1498Szrj #endif
197238fd1498Szrj 
197338fd1498Szrj _GLIBCXX_END_NAMESPACE_CXX11
197438fd1498Szrj 
197538fd1498Szrj   /**
197638fd1498Szrj    *  @brief  List equality comparison.
197738fd1498Szrj    *  @param  __x  A %list.
197838fd1498Szrj    *  @param  __y  A %list of the same type as @a __x.
197938fd1498Szrj    *  @return  True iff the size and elements of the lists are equal.
198038fd1498Szrj    *
198138fd1498Szrj    *  This is an equivalence relation.  It is linear in the size of
198238fd1498Szrj    *  the lists.  Lists are considered equivalent if their sizes are
198338fd1498Szrj    *  equal, and if corresponding elements compare equal.
198438fd1498Szrj   */
198538fd1498Szrj   template<typename _Tp, typename _Alloc>
198638fd1498Szrj     inline bool
198738fd1498Szrj     operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
198838fd1498Szrj     {
198938fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
199038fd1498Szrj       if (__x.size() != __y.size())
199138fd1498Szrj 	return false;
199238fd1498Szrj #endif
199338fd1498Szrj 
199438fd1498Szrj       typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
199538fd1498Szrj       const_iterator __end1 = __x.end();
199638fd1498Szrj       const_iterator __end2 = __y.end();
199738fd1498Szrj 
199838fd1498Szrj       const_iterator __i1 = __x.begin();
199938fd1498Szrj       const_iterator __i2 = __y.begin();
200038fd1498Szrj       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
200138fd1498Szrj 	{
200238fd1498Szrj 	  ++__i1;
200338fd1498Szrj 	  ++__i2;
200438fd1498Szrj 	}
200538fd1498Szrj       return __i1 == __end1 && __i2 == __end2;
200638fd1498Szrj     }
200738fd1498Szrj 
200838fd1498Szrj   /**
200938fd1498Szrj    *  @brief  List ordering relation.
201038fd1498Szrj    *  @param  __x  A %list.
201138fd1498Szrj    *  @param  __y  A %list of the same type as @a __x.
201238fd1498Szrj    *  @return  True iff @a __x is lexicographically less than @a __y.
201338fd1498Szrj    *
201438fd1498Szrj    *  This is a total ordering relation.  It is linear in the size of the
201538fd1498Szrj    *  lists.  The elements must be comparable with @c <.
201638fd1498Szrj    *
201738fd1498Szrj    *  See std::lexicographical_compare() for how the determination is made.
201838fd1498Szrj   */
201938fd1498Szrj   template<typename _Tp, typename _Alloc>
202038fd1498Szrj     inline bool
202138fd1498Szrj     operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
202238fd1498Szrj     { return std::lexicographical_compare(__x.begin(), __x.end(),
202338fd1498Szrj 					  __y.begin(), __y.end()); }
202438fd1498Szrj 
202538fd1498Szrj   /// Based on operator==
202638fd1498Szrj   template<typename _Tp, typename _Alloc>
202738fd1498Szrj     inline bool
202838fd1498Szrj     operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
202938fd1498Szrj     { return !(__x == __y); }
203038fd1498Szrj 
203138fd1498Szrj   /// Based on operator<
203238fd1498Szrj   template<typename _Tp, typename _Alloc>
203338fd1498Szrj     inline bool
203438fd1498Szrj     operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
203538fd1498Szrj     { return __y < __x; }
203638fd1498Szrj 
203738fd1498Szrj   /// Based on operator<
203838fd1498Szrj   template<typename _Tp, typename _Alloc>
203938fd1498Szrj     inline bool
204038fd1498Szrj     operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
204138fd1498Szrj     { return !(__y < __x); }
204238fd1498Szrj 
204338fd1498Szrj   /// Based on operator<
204438fd1498Szrj   template<typename _Tp, typename _Alloc>
204538fd1498Szrj     inline bool
204638fd1498Szrj     operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
204738fd1498Szrj     { return !(__x < __y); }
204838fd1498Szrj 
204938fd1498Szrj   /// See std::list::swap().
205038fd1498Szrj   template<typename _Tp, typename _Alloc>
205138fd1498Szrj     inline void
205238fd1498Szrj     swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
205338fd1498Szrj     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
205438fd1498Szrj     { __x.swap(__y); }
205538fd1498Szrj 
205638fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER
205738fd1498Szrj 
205838fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI
205938fd1498Szrj 
206038fd1498Szrj   // Detect when distance is used to compute the size of the whole list.
206138fd1498Szrj   template<typename _Tp>
206238fd1498Szrj     inline ptrdiff_t
206338fd1498Szrj     __distance(_GLIBCXX_STD_C::_List_iterator<_Tp> __first,
206438fd1498Szrj 	       _GLIBCXX_STD_C::_List_iterator<_Tp> __last,
206538fd1498Szrj 	       input_iterator_tag __tag)
206638fd1498Szrj     {
206738fd1498Szrj       typedef _GLIBCXX_STD_C::_List_const_iterator<_Tp> _CIter;
206838fd1498Szrj       return std::__distance(_CIter(__first), _CIter(__last), __tag);
206938fd1498Szrj     }
207038fd1498Szrj 
207138fd1498Szrj   template<typename _Tp>
207238fd1498Szrj     inline ptrdiff_t
207338fd1498Szrj     __distance(_GLIBCXX_STD_C::_List_const_iterator<_Tp> __first,
207438fd1498Szrj 	       _GLIBCXX_STD_C::_List_const_iterator<_Tp> __last,
207538fd1498Szrj 	       input_iterator_tag)
207638fd1498Szrj     {
207738fd1498Szrj       typedef __detail::_List_node_header _Sentinel;
207838fd1498Szrj       _GLIBCXX_STD_C::_List_const_iterator<_Tp> __beyond = __last;
207938fd1498Szrj       ++__beyond;
208038fd1498Szrj       const bool __whole = __first == __beyond;
208138fd1498Szrj       if (__builtin_constant_p (__whole) && __whole)
208238fd1498Szrj 	return static_cast<const _Sentinel*>(__last._M_node)->_M_size;
208338fd1498Szrj 
208438fd1498Szrj       ptrdiff_t __n = 0;
208538fd1498Szrj       while (__first != __last)
208638fd1498Szrj 	{
208738fd1498Szrj 	  ++__first;
208838fd1498Szrj 	  ++__n;
208938fd1498Szrj 	}
209038fd1498Szrj       return __n;
209138fd1498Szrj     }
209238fd1498Szrj #endif
209338fd1498Szrj 
209438fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
209538fd1498Szrj } // namespace std
209638fd1498Szrj 
209738fd1498Szrj #endif /* _STL_LIST_H */
2098