libstdc++
stl_list.h
Go to the documentation of this file.
1 // List implementation -*- C++ -*-
2 
3 // Copyright (C) 2001-2014 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /*
26  *
27  * Copyright (c) 1994
28  * Hewlett-Packard Company
29  *
30  * Permission to use, copy, modify, distribute and sell this software
31  * and its documentation for any purpose is hereby granted without fee,
32  * provided that the above copyright notice appear in all copies and
33  * that both that copyright notice and this permission notice appear
34  * in supporting documentation. Hewlett-Packard Company makes no
35  * representations about the suitability of this software for any
36  * purpose. It is provided "as is" without express or implied warranty.
37  *
38  *
39  * Copyright (c) 1996,1997
40  * Silicon Graphics Computer Systems, Inc.
41  *
42  * Permission to use, copy, modify, distribute and sell this software
43  * and its documentation for any purpose is hereby granted without fee,
44  * provided that the above copyright notice appear in all copies and
45  * that both that copyright notice and this permission notice appear
46  * in supporting documentation. Silicon Graphics makes no
47  * representations about the suitability of this software for any
48  * purpose. It is provided "as is" without express or implied warranty.
49  */
50 
51 /** @file bits/stl_list.h
52  * This is an internal header file, included by other library headers.
53  * Do not attempt to use it directly. @headername{list}
54  */
55 
56 #ifndef _STL_LIST_H
57 #define _STL_LIST_H 1
58 
59 #include <bits/concept_check.h>
60 #if __cplusplus >= 201103L
61 #include <initializer_list>
62 #endif
63 
64 namespace std _GLIBCXX_VISIBILITY(default)
65 {
66  namespace __detail
67  {
68  _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 
70  // Supporting structures are split into common and templated
71  // types; the latter publicly inherits from the former in an
72  // effort to reduce code duplication. This results in some
73  // "needless" static_cast'ing later on, but it's all safe
74  // downcasting.
75 
76  /// Common part of a node in the %list.
78  {
79  _List_node_base* _M_next;
80  _List_node_base* _M_prev;
81 
82  static void
83  swap(_List_node_base& __x, _List_node_base& __y) _GLIBCXX_USE_NOEXCEPT;
84 
85  void
86  _M_transfer(_List_node_base* const __first,
87  _List_node_base* const __last) _GLIBCXX_USE_NOEXCEPT;
88 
89  void
90  _M_reverse() _GLIBCXX_USE_NOEXCEPT;
91 
92  void
93  _M_hook(_List_node_base* const __position) _GLIBCXX_USE_NOEXCEPT;
94 
95  void
96  _M_unhook() _GLIBCXX_USE_NOEXCEPT;
97  };
98 
99  _GLIBCXX_END_NAMESPACE_VERSION
100  } // namespace detail
101 
102 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
103 
104  /// An actual node in the %list.
105  template<typename _Tp>
107  {
108  ///< User's data.
109  _Tp _M_data;
110 
111 #if __cplusplus >= 201103L
112  template<typename... _Args>
113  _List_node(_Args&&... __args)
114  : __detail::_List_node_base(), _M_data(std::forward<_Args>(__args)...)
115  { }
116 #endif
117  };
118 
119  /**
120  * @brief A list::iterator.
121  *
122  * All the functions are op overloads.
123  */
124  template<typename _Tp>
126  {
127  typedef _List_iterator<_Tp> _Self;
128  typedef _List_node<_Tp> _Node;
129 
130  typedef ptrdiff_t difference_type;
132  typedef _Tp value_type;
133  typedef _Tp* pointer;
134  typedef _Tp& reference;
135 
136  _List_iterator() _GLIBCXX_NOEXCEPT
137  : _M_node() { }
138 
139  explicit
140  _List_iterator(__detail::_List_node_base* __x) _GLIBCXX_NOEXCEPT
141  : _M_node(__x) { }
142 
143  _Self
144  _M_const_cast() const _GLIBCXX_NOEXCEPT
145  { return *this; }
146 
147  // Must downcast from _List_node_base to _List_node to get to _M_data.
148  reference
149  operator*() const _GLIBCXX_NOEXCEPT
150  { return static_cast<_Node*>(_M_node)->_M_data; }
151 
152  pointer
153  operator->() const _GLIBCXX_NOEXCEPT
154  { return std::__addressof(static_cast<_Node*>(_M_node)->_M_data); }
155 
156  _Self&
157  operator++() _GLIBCXX_NOEXCEPT
158  {
159  _M_node = _M_node->_M_next;
160  return *this;
161  }
162 
163  _Self
164  operator++(int) _GLIBCXX_NOEXCEPT
165  {
166  _Self __tmp = *this;
167  _M_node = _M_node->_M_next;
168  return __tmp;
169  }
170 
171  _Self&
172  operator--() _GLIBCXX_NOEXCEPT
173  {
174  _M_node = _M_node->_M_prev;
175  return *this;
176  }
177 
178  _Self
179  operator--(int) _GLIBCXX_NOEXCEPT
180  {
181  _Self __tmp = *this;
182  _M_node = _M_node->_M_prev;
183  return __tmp;
184  }
185 
186  bool
187  operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
188  { return _M_node == __x._M_node; }
189 
190  bool
191  operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
192  { return _M_node != __x._M_node; }
193 
194  // The only member points to the %list element.
195  __detail::_List_node_base* _M_node;
196  };
197 
198  /**
199  * @brief A list::const_iterator.
200  *
201  * All the functions are op overloads.
202  */
203  template<typename _Tp>
205  {
207  typedef const _List_node<_Tp> _Node;
209 
210  typedef ptrdiff_t difference_type;
212  typedef _Tp value_type;
213  typedef const _Tp* pointer;
214  typedef const _Tp& reference;
215 
216  _List_const_iterator() _GLIBCXX_NOEXCEPT
217  : _M_node() { }
218 
219  explicit
221  _GLIBCXX_NOEXCEPT
222  : _M_node(__x) { }
223 
224  _List_const_iterator(const iterator& __x) _GLIBCXX_NOEXCEPT
225  : _M_node(__x._M_node) { }
226 
227  iterator
228  _M_const_cast() const _GLIBCXX_NOEXCEPT
229  { return iterator(const_cast<__detail::_List_node_base*>(_M_node)); }
230 
231  // Must downcast from List_node_base to _List_node to get to
232  // _M_data.
233  reference
234  operator*() const _GLIBCXX_NOEXCEPT
235  { return static_cast<_Node*>(_M_node)->_M_data; }
236 
237  pointer
238  operator->() const _GLIBCXX_NOEXCEPT
239  { return std::__addressof(static_cast<_Node*>(_M_node)->_M_data); }
240 
241  _Self&
242  operator++() _GLIBCXX_NOEXCEPT
243  {
244  _M_node = _M_node->_M_next;
245  return *this;
246  }
247 
248  _Self
249  operator++(int) _GLIBCXX_NOEXCEPT
250  {
251  _Self __tmp = *this;
252  _M_node = _M_node->_M_next;
253  return __tmp;
254  }
255 
256  _Self&
257  operator--() _GLIBCXX_NOEXCEPT
258  {
259  _M_node = _M_node->_M_prev;
260  return *this;
261  }
262 
263  _Self
264  operator--(int) _GLIBCXX_NOEXCEPT
265  {
266  _Self __tmp = *this;
267  _M_node = _M_node->_M_prev;
268  return __tmp;
269  }
270 
271  bool
272  operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT
273  { return _M_node == __x._M_node; }
274 
275  bool
276  operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT
277  { return _M_node != __x._M_node; }
278 
279  // The only member points to the %list element.
280  const __detail::_List_node_base* _M_node;
281  };
282 
283  template<typename _Val>
284  inline bool
285  operator==(const _List_iterator<_Val>& __x,
286  const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
287  { return __x._M_node == __y._M_node; }
288 
289  template<typename _Val>
290  inline bool
291  operator!=(const _List_iterator<_Val>& __x,
292  const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT
293  { return __x._M_node != __y._M_node; }
294 
295 
296  /// See bits/stl_deque.h's _Deque_base for an explanation.
297  template<typename _Tp, typename _Alloc>
299  {
300  protected:
301  // NOTA BENE
302  // The stored instance is not actually of "allocator_type"'s
303  // type. Instead we rebind the type to
304  // Allocator<List_node<Tp>>, which according to [20.1.5]/4
305  // should probably be the same. List_node<Tp> is not the same
306  // size as Tp (it's two pointers larger), and specializations on
307  // Tp may go unused because List_node<Tp> is being bound
308  // instead.
309  //
310  // We put this to the test in the constructors and in
311  // get_allocator, where we use conversions between
312  // allocator_type and _Node_alloc_type. The conversion is
313  // required by table 32 in [20.1.5].
314  typedef typename _Alloc::template rebind<_List_node<_Tp> >::other
315  _Node_alloc_type;
316 
317  typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
318 
319  struct _List_impl
320  : public _Node_alloc_type
321  {
323 
324  _List_impl()
325  : _Node_alloc_type(), _M_node()
326  { }
327 
328  _List_impl(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT
329  : _Node_alloc_type(__a), _M_node()
330  { }
331 
332 #if __cplusplus >= 201103L
333  _List_impl(_Node_alloc_type&& __a) _GLIBCXX_NOEXCEPT
334  : _Node_alloc_type(std::move(__a)), _M_node()
335  { }
336 #endif
337  };
338 
339  _List_impl _M_impl;
340 
342  _M_get_node()
343  { return _M_impl._Node_alloc_type::allocate(1); }
344 
345  void
346  _M_put_node(_List_node<_Tp>* __p) _GLIBCXX_NOEXCEPT
347  { _M_impl._Node_alloc_type::deallocate(__p, 1); }
348 
349  public:
350  typedef _Alloc allocator_type;
351 
352  _Node_alloc_type&
353  _M_get_Node_allocator() _GLIBCXX_NOEXCEPT
354  { return *static_cast<_Node_alloc_type*>(&_M_impl); }
355 
356  const _Node_alloc_type&
357  _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
358  { return *static_cast<const _Node_alloc_type*>(&_M_impl); }
359 
360  _Tp_alloc_type
361  _M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT
362  { return _Tp_alloc_type(_M_get_Node_allocator()); }
363 
364  allocator_type
365  get_allocator() const _GLIBCXX_NOEXCEPT
366  { return allocator_type(_M_get_Node_allocator()); }
367 
368  _List_base()
369  : _M_impl()
370  { _M_init(); }
371 
372  _List_base(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT
373  : _M_impl(__a)
374  { _M_init(); }
375 
376 #if __cplusplus >= 201103L
377  _List_base(_List_base&& __x) noexcept
378  : _M_impl(std::move(__x._M_get_Node_allocator()))
379  {
380  _M_init();
381  __detail::_List_node_base::swap(_M_impl._M_node, __x._M_impl._M_node);
382  }
383 #endif
384 
385  // This is what actually destroys the list.
386  ~_List_base() _GLIBCXX_NOEXCEPT
387  { _M_clear(); }
388 
389  void
390  _M_clear() _GLIBCXX_NOEXCEPT;
391 
392  void
393  _M_init() _GLIBCXX_NOEXCEPT
394  {
395  this->_M_impl._M_node._M_next = &this->_M_impl._M_node;
396  this->_M_impl._M_node._M_prev = &this->_M_impl._M_node;
397  }
398  };
399 
400  /**
401  * @brief A standard container with linear time access to elements,
402  * and fixed time insertion/deletion at any point in the sequence.
403  *
404  * @ingroup sequences
405  *
406  * @tparam _Tp Type of element.
407  * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
408  *
409  * Meets the requirements of a <a href="tables.html#65">container</a>, a
410  * <a href="tables.html#66">reversible container</a>, and a
411  * <a href="tables.html#67">sequence</a>, including the
412  * <a href="tables.html#68">optional sequence requirements</a> with the
413  * %exception of @c at and @c operator[].
414  *
415  * This is a @e doubly @e linked %list. Traversal up and down the
416  * %list requires linear time, but adding and removing elements (or
417  * @e nodes) is done in constant time, regardless of where the
418  * change takes place. Unlike std::vector and std::deque,
419  * random-access iterators are not provided, so subscripting ( @c
420  * [] ) access is not allowed. For algorithms which only need
421  * sequential access, this lack makes no difference.
422  *
423  * Also unlike the other standard containers, std::list provides
424  * specialized algorithms %unique to linked lists, such as
425  * splicing, sorting, and in-place reversal.
426  *
427  * A couple points on memory allocation for list<Tp>:
428  *
429  * First, we never actually allocate a Tp, we allocate
430  * List_node<Tp>'s and trust [20.1.5]/4 to DTRT. This is to ensure
431  * that after elements from %list<X,Alloc1> are spliced into
432  * %list<X,Alloc2>, destroying the memory of the second %list is a
433  * valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
434  *
435  * Second, a %list conceptually represented as
436  * @code
437  * A <---> B <---> C <---> D
438  * @endcode
439  * is actually circular; a link exists between A and D. The %list
440  * class holds (as its only data member) a private list::iterator
441  * pointing to @e D, not to @e A! To get to the head of the %list,
442  * we start at the tail and move forward by one. When this member
443  * iterator's next/previous pointers refer to itself, the %list is
444  * %empty.
445  */
446  template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
447  class list : protected _List_base<_Tp, _Alloc>
448  {
449  // concept requirements
450  typedef typename _Alloc::value_type _Alloc_value_type;
451  __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
452  __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
453 
455  typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
456  typedef typename _Base::_Node_alloc_type _Node_alloc_type;
457 
458  public:
459  typedef _Tp value_type;
460  typedef typename _Tp_alloc_type::pointer pointer;
461  typedef typename _Tp_alloc_type::const_pointer const_pointer;
462  typedef typename _Tp_alloc_type::reference reference;
463  typedef typename _Tp_alloc_type::const_reference const_reference;
468  typedef size_t size_type;
469  typedef ptrdiff_t difference_type;
470  typedef _Alloc allocator_type;
471 
472  protected:
473  // Note that pointers-to-_Node's can be ctor-converted to
474  // iterator types.
475  typedef _List_node<_Tp> _Node;
476 
477  using _Base::_M_impl;
478  using _Base::_M_put_node;
479  using _Base::_M_get_node;
480  using _Base::_M_get_Tp_allocator;
481  using _Base::_M_get_Node_allocator;
482 
483  /**
484  * @param __args An instance of user data.
485  *
486  * Allocates space for a new node and constructs a copy of
487  * @a __args in it.
488  */
489 #if __cplusplus < 201103L
490  _Node*
491  _M_create_node(const value_type& __x)
492  {
493  _Node* __p = this->_M_get_node();
494  __try
495  {
496  _M_get_Tp_allocator().construct
497  (std::__addressof(__p->_M_data), __x);
498  }
499  __catch(...)
500  {
501  _M_put_node(__p);
502  __throw_exception_again;
503  }
504  return __p;
505  }
506 #else
507  template<typename... _Args>
508  _Node*
509  _M_create_node(_Args&&... __args)
510  {
511  _Node* __p = this->_M_get_node();
512  __try
513  {
514  _M_get_Node_allocator().construct(__p,
515  std::forward<_Args>(__args)...);
516  }
517  __catch(...)
518  {
519  _M_put_node(__p);
520  __throw_exception_again;
521  }
522  return __p;
523  }
524 #endif
525 
526  public:
527  // [23.2.2.1] construct/copy/destroy
528  // (assign() and get_allocator() are also listed in this section)
529  /**
530  * @brief Creates a %list with no elements.
531  * @param __a An allocator object.
532  */
533  explicit
534  list(const allocator_type& __a = allocator_type()) _GLIBCXX_NOEXCEPT
535  : _Base(_Node_alloc_type(__a)) { }
536 
537 #if __cplusplus >= 201103L
538  /**
539  * @brief Creates a %list with default constructed elements.
540  * @param __n The number of elements to initially create.
541  *
542  * This constructor fills the %list with @a __n default
543  * constructed elements.
544  */
545  explicit
546  list(size_type __n)
547  : _Base()
548  { _M_default_initialize(__n); }
549 
550  /**
551  * @brief Creates a %list with copies of an exemplar element.
552  * @param __n The number of elements to initially create.
553  * @param __value An element to copy.
554  * @param __a An allocator object.
555  *
556  * This constructor fills the %list with @a __n copies of @a __value.
557  */
558  list(size_type __n, const value_type& __value,
559  const allocator_type& __a = allocator_type())
560  : _Base(_Node_alloc_type(__a))
561  { _M_fill_initialize(__n, __value); }
562 #else
563  /**
564  * @brief Creates a %list with copies of an exemplar element.
565  * @param __n The number of elements to initially create.
566  * @param __value An element to copy.
567  * @param __a An allocator object.
568  *
569  * This constructor fills the %list with @a __n copies of @a __value.
570  */
571  explicit
572  list(size_type __n, const value_type& __value = value_type(),
573  const allocator_type& __a = allocator_type())
574  : _Base(_Node_alloc_type(__a))
575  { _M_fill_initialize(__n, __value); }
576 #endif
577 
578  /**
579  * @brief %List copy constructor.
580  * @param __x A %list of identical element and allocator types.
581  *
582  * The newly-created %list uses a copy of the allocation object used
583  * by @a __x.
584  */
585  list(const list& __x)
586  : _Base(__x._M_get_Node_allocator())
587  { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
588 
589 #if __cplusplus >= 201103L
590  /**
591  * @brief %List move constructor.
592  * @param __x A %list of identical element and allocator types.
593  *
594  * The newly-created %list contains the exact contents of @a __x.
595  * The contents of @a __x are a valid, but unspecified %list.
596  */
597  list(list&& __x) noexcept
598  : _Base(std::move(__x)) { }
599 
600  /**
601  * @brief Builds a %list from an initializer_list
602  * @param __l An initializer_list of value_type.
603  * @param __a An allocator object.
604  *
605  * Create a %list consisting of copies of the elements in the
606  * initializer_list @a __l. This is linear in __l.size().
607  */
609  const allocator_type& __a = allocator_type())
610  : _Base(_Node_alloc_type(__a))
611  { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); }
612 #endif
613 
614  /**
615  * @brief Builds a %list from a range.
616  * @param __first An input iterator.
617  * @param __last An input iterator.
618  * @param __a An allocator object.
619  *
620  * Create a %list consisting of copies of the elements from
621  * [@a __first,@a __last). This is linear in N (where N is
622  * distance(@a __first,@a __last)).
623  */
624 #if __cplusplus >= 201103L
625  template<typename _InputIterator,
626  typename = std::_RequireInputIter<_InputIterator>>
627  list(_InputIterator __first, _InputIterator __last,
628  const allocator_type& __a = allocator_type())
629  : _Base(_Node_alloc_type(__a))
630  { _M_initialize_dispatch(__first, __last, __false_type()); }
631 #else
632  template<typename _InputIterator>
633  list(_InputIterator __first, _InputIterator __last,
634  const allocator_type& __a = allocator_type())
635  : _Base(_Node_alloc_type(__a))
636  {
637  // Check whether it's an integral type. If so, it's not an iterator.
638  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
639  _M_initialize_dispatch(__first, __last, _Integral());
640  }
641 #endif
642 
643  /**
644  * No explicit dtor needed as the _Base dtor takes care of
645  * things. The _Base dtor only erases the elements, and note
646  * that if the elements themselves are pointers, the pointed-to
647  * memory is not touched in any way. Managing the pointer is
648  * the user's responsibility.
649  */
650 
651  /**
652  * @brief %List assignment operator.
653  * @param __x A %list of identical element and allocator types.
654  *
655  * All the elements of @a __x are copied, but unlike the copy
656  * constructor, the allocator object is not copied.
657  */
658  list&
659  operator=(const list& __x);
660 
661 #if __cplusplus >= 201103L
662  /**
663  * @brief %List move assignment operator.
664  * @param __x A %list of identical element and allocator types.
665  *
666  * The contents of @a __x are moved into this %list (without copying).
667  * @a __x is a valid, but unspecified %list
668  */
669  list&
671  {
672  // NB: DR 1204.
673  // NB: DR 675.
674  this->clear();
675  this->swap(__x);
676  return *this;
677  }
678 
679  /**
680  * @brief %List initializer list assignment operator.
681  * @param __l An initializer_list of value_type.
682  *
683  * Replace the contents of the %list with copies of the elements
684  * in the initializer_list @a __l. This is linear in l.size().
685  */
686  list&
688  {
689  this->assign(__l.begin(), __l.end());
690  return *this;
691  }
692 #endif
693 
694  /**
695  * @brief Assigns a given value to a %list.
696  * @param __n Number of elements to be assigned.
697  * @param __val Value to be assigned.
698  *
699  * This function fills a %list with @a __n copies of the given
700  * value. Note that the assignment completely changes the %list
701  * and that the resulting %list's size is the same as the number
702  * of elements assigned. Old data may be lost.
703  */
704  void
705  assign(size_type __n, const value_type& __val)
706  { _M_fill_assign(__n, __val); }
707 
708  /**
709  * @brief Assigns a range to a %list.
710  * @param __first An input iterator.
711  * @param __last An input iterator.
712  *
713  * This function fills a %list with copies of the elements in the
714  * range [@a __first,@a __last).
715  *
716  * Note that the assignment completely changes the %list and
717  * that the resulting %list's size is the same as the number of
718  * elements assigned. Old data may be lost.
719  */
720 #if __cplusplus >= 201103L
721  template<typename _InputIterator,
722  typename = std::_RequireInputIter<_InputIterator>>
723  void
724  assign(_InputIterator __first, _InputIterator __last)
725  { _M_assign_dispatch(__first, __last, __false_type()); }
726 #else
727  template<typename _InputIterator>
728  void
729  assign(_InputIterator __first, _InputIterator __last)
730  {
731  // Check whether it's an integral type. If so, it's not an iterator.
732  typedef typename std::__is_integer<_InputIterator>::__type _Integral;
733  _M_assign_dispatch(__first, __last, _Integral());
734  }
735 #endif
736 
737 #if __cplusplus >= 201103L
738  /**
739  * @brief Assigns an initializer_list to a %list.
740  * @param __l An initializer_list of value_type.
741  *
742  * Replace the contents of the %list with copies of the elements
743  * in the initializer_list @a __l. This is linear in __l.size().
744  */
745  void
747  { this->assign(__l.begin(), __l.end()); }
748 #endif
749 
750  /// Get a copy of the memory allocation object.
751  allocator_type
752  get_allocator() const _GLIBCXX_NOEXCEPT
753  { return _Base::get_allocator(); }
754 
755  // iterators
756  /**
757  * Returns a read/write iterator that points to the first element in the
758  * %list. Iteration is done in ordinary element order.
759  */
760  iterator
761  begin() _GLIBCXX_NOEXCEPT
762  { return iterator(this->_M_impl._M_node._M_next); }
763 
764  /**
765  * Returns a read-only (constant) iterator that points to the
766  * first element in the %list. Iteration is done in ordinary
767  * element order.
768  */
769  const_iterator
770  begin() const _GLIBCXX_NOEXCEPT
771  { return const_iterator(this->_M_impl._M_node._M_next); }
772 
773  /**
774  * Returns a read/write iterator that points one past the last
775  * element in the %list. Iteration is done in ordinary element
776  * order.
777  */
778  iterator
779  end() _GLIBCXX_NOEXCEPT
780  { return iterator(&this->_M_impl._M_node); }
781 
782  /**
783  * Returns a read-only (constant) iterator that points one past
784  * the last element in the %list. Iteration is done in ordinary
785  * element order.
786  */
787  const_iterator
788  end() const _GLIBCXX_NOEXCEPT
789  { return const_iterator(&this->_M_impl._M_node); }
790 
791  /**
792  * Returns a read/write reverse iterator that points to the last
793  * element in the %list. Iteration is done in reverse element
794  * order.
795  */
797  rbegin() _GLIBCXX_NOEXCEPT
798  { return reverse_iterator(end()); }
799 
800  /**
801  * Returns a read-only (constant) reverse iterator that points to
802  * the last element in the %list. Iteration is done in reverse
803  * element order.
804  */
805  const_reverse_iterator
806  rbegin() const _GLIBCXX_NOEXCEPT
807  { return const_reverse_iterator(end()); }
808 
809  /**
810  * Returns a read/write reverse iterator that points to one
811  * before the first element in the %list. Iteration is done in
812  * reverse element order.
813  */
815  rend() _GLIBCXX_NOEXCEPT
816  { return reverse_iterator(begin()); }
817 
818  /**
819  * Returns a read-only (constant) reverse iterator that points to one
820  * before the first element in the %list. Iteration is done in reverse
821  * element order.
822  */
823  const_reverse_iterator
824  rend() const _GLIBCXX_NOEXCEPT
825  { return const_reverse_iterator(begin()); }
826 
827 #if __cplusplus >= 201103L
828  /**
829  * Returns a read-only (constant) iterator that points to the
830  * first element in the %list. Iteration is done in ordinary
831  * element order.
832  */
833  const_iterator
834  cbegin() const noexcept
835  { return const_iterator(this->_M_impl._M_node._M_next); }
836 
837  /**
838  * Returns a read-only (constant) iterator that points one past
839  * the last element in the %list. Iteration is done in ordinary
840  * element order.
841  */
842  const_iterator
843  cend() const noexcept
844  { return const_iterator(&this->_M_impl._M_node); }
845 
846  /**
847  * Returns a read-only (constant) reverse iterator that points to
848  * the last element in the %list. Iteration is done in reverse
849  * element order.
850  */
851  const_reverse_iterator
852  crbegin() const noexcept
853  { return const_reverse_iterator(end()); }
854 
855  /**
856  * Returns a read-only (constant) reverse iterator that points to one
857  * before the first element in the %list. Iteration is done in reverse
858  * element order.
859  */
860  const_reverse_iterator
861  crend() const noexcept
862  { return const_reverse_iterator(begin()); }
863 #endif
864 
865  // [23.2.2.2] capacity
866  /**
867  * Returns true if the %list is empty. (Thus begin() would equal
868  * end().)
869  */
870  bool
871  empty() const _GLIBCXX_NOEXCEPT
872  { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
873 
874  /** Returns the number of elements in the %list. */
875  size_type
876  size() const _GLIBCXX_NOEXCEPT
877  { return std::distance(begin(), end()); }
878 
879  /** Returns the size() of the largest possible %list. */
880  size_type
881  max_size() const _GLIBCXX_NOEXCEPT
882  { return _M_get_Node_allocator().max_size(); }
883 
884 #if __cplusplus >= 201103L
885  /**
886  * @brief Resizes the %list to the specified number of elements.
887  * @param __new_size Number of elements the %list should contain.
888  *
889  * This function will %resize the %list to the specified number
890  * of elements. If the number is smaller than the %list's
891  * current size the %list is truncated, otherwise default
892  * constructed elements are appended.
893  */
894  void
895  resize(size_type __new_size);
896 
897  /**
898  * @brief Resizes the %list to the specified number of elements.
899  * @param __new_size Number of elements the %list should contain.
900  * @param __x Data with which new elements should be populated.
901  *
902  * This function will %resize the %list to the specified number
903  * of elements. If the number is smaller than the %list's
904  * current size the %list is truncated, otherwise the %list is
905  * extended and new elements are populated with given data.
906  */
907  void
908  resize(size_type __new_size, const value_type& __x);
909 #else
910  /**
911  * @brief Resizes the %list to the specified number of elements.
912  * @param __new_size Number of elements the %list should contain.
913  * @param __x Data with which new elements should be populated.
914  *
915  * This function will %resize the %list to the specified number
916  * of elements. If the number is smaller than the %list's
917  * current size the %list is truncated, otherwise the %list is
918  * extended and new elements are populated with given data.
919  */
920  void
921  resize(size_type __new_size, value_type __x = value_type());
922 #endif
923 
924  // element access
925  /**
926  * Returns a read/write reference to the data at the first
927  * element of the %list.
928  */
929  reference
930  front() _GLIBCXX_NOEXCEPT
931  { return *begin(); }
932 
933  /**
934  * Returns a read-only (constant) reference to the data at the first
935  * element of the %list.
936  */
937  const_reference
938  front() const _GLIBCXX_NOEXCEPT
939  { return *begin(); }
940 
941  /**
942  * Returns a read/write reference to the data at the last element
943  * of the %list.
944  */
945  reference
946  back() _GLIBCXX_NOEXCEPT
947  {
948  iterator __tmp = end();
949  --__tmp;
950  return *__tmp;
951  }
952 
953  /**
954  * Returns a read-only (constant) reference to the data at the last
955  * element of the %list.
956  */
957  const_reference
958  back() const _GLIBCXX_NOEXCEPT
959  {
960  const_iterator __tmp = end();
961  --__tmp;
962  return *__tmp;
963  }
964 
965  // [23.2.2.3] modifiers
966  /**
967  * @brief Add data to the front of the %list.
968  * @param __x Data to be added.
969  *
970  * This is a typical stack operation. The function creates an
971  * element at the front of the %list and assigns the given data
972  * to it. Due to the nature of a %list this operation can be
973  * done in constant time, and does not invalidate iterators and
974  * references.
975  */
976  void
977  push_front(const value_type& __x)
978  { this->_M_insert(begin(), __x); }
979 
980 #if __cplusplus >= 201103L
981  void
982  push_front(value_type&& __x)
983  { this->_M_insert(begin(), std::move(__x)); }
984 
985  template<typename... _Args>
986  void
987  emplace_front(_Args&&... __args)
988  { this->_M_insert(begin(), std::forward<_Args>(__args)...); }
989 #endif
990 
991  /**
992  * @brief Removes first element.
993  *
994  * This is a typical stack operation. It shrinks the %list by
995  * one. Due to the nature of a %list this operation can be done
996  * in constant time, and only invalidates iterators/references to
997  * the element being removed.
998  *
999  * Note that no data is returned, and if the first element's data
1000  * is needed, it should be retrieved before pop_front() is
1001  * called.
1002  */
1003  void
1004  pop_front() _GLIBCXX_NOEXCEPT
1005  { this->_M_erase(begin()); }
1006 
1007  /**
1008  * @brief Add data to the end of the %list.
1009  * @param __x Data to be added.
1010  *
1011  * This is a typical stack operation. The function creates an
1012  * element at the end of the %list and assigns the given data to
1013  * it. Due to the nature of a %list this operation can be done
1014  * in constant time, and does not invalidate iterators and
1015  * references.
1016  */
1017  void
1018  push_back(const value_type& __x)
1019  { this->_M_insert(end(), __x); }
1020 
1021 #if __cplusplus >= 201103L
1022  void
1023  push_back(value_type&& __x)
1024  { this->_M_insert(end(), std::move(__x)); }
1025 
1026  template<typename... _Args>
1027  void
1028  emplace_back(_Args&&... __args)
1029  { this->_M_insert(end(), std::forward<_Args>(__args)...); }
1030 #endif
1031 
1032  /**
1033  * @brief Removes last element.
1034  *
1035  * This is a typical stack operation. It shrinks the %list by
1036  * one. Due to the nature of a %list this operation can be done
1037  * in constant time, and only invalidates iterators/references to
1038  * the element being removed.
1039  *
1040  * Note that no data is returned, and if the last element's data
1041  * is needed, it should be retrieved before pop_back() is called.
1042  */
1043  void
1044  pop_back() _GLIBCXX_NOEXCEPT
1045  { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
1046 
1047 #if __cplusplus >= 201103L
1048  /**
1049  * @brief Constructs object in %list before specified iterator.
1050  * @param __position A const_iterator into the %list.
1051  * @param __args Arguments.
1052  * @return An iterator that points to the inserted data.
1053  *
1054  * This function will insert an object of type T constructed
1055  * with T(std::forward<Args>(args)...) before the specified
1056  * location. Due to the nature of a %list this operation can
1057  * be done in constant time, and does not invalidate iterators
1058  * and references.
1059  */
1060  template<typename... _Args>
1061  iterator
1062  emplace(const_iterator __position, _Args&&... __args);
1063 
1064  /**
1065  * @brief Inserts given value into %list before specified iterator.
1066  * @param __position A const_iterator into the %list.
1067  * @param __x Data to be inserted.
1068  * @return An iterator that points to the inserted data.
1069  *
1070  * This function will insert a copy of the given value before
1071  * the specified location. Due to the nature of a %list this
1072  * operation can be done in constant time, and does not
1073  * invalidate iterators and references.
1074  */
1075  iterator
1076  insert(const_iterator __position, const value_type& __x);
1077 #else
1078  /**
1079  * @brief Inserts given value into %list before specified iterator.
1080  * @param __position An iterator into the %list.
1081  * @param __x Data to be inserted.
1082  * @return An iterator that points to the inserted data.
1083  *
1084  * This function will insert a copy of the given value before
1085  * the specified location. Due to the nature of a %list this
1086  * operation can be done in constant time, and does not
1087  * invalidate iterators and references.
1088  */
1089  iterator
1090  insert(iterator __position, const value_type& __x);
1091 #endif
1092 
1093 #if __cplusplus >= 201103L
1094  /**
1095  * @brief Inserts given rvalue into %list before specified iterator.
1096  * @param __position A const_iterator into the %list.
1097  * @param __x Data to be inserted.
1098  * @return An iterator that points to the inserted data.
1099  *
1100  * This function will insert a copy of the given rvalue before
1101  * the specified location. Due to the nature of a %list this
1102  * operation can be done in constant time, and does not
1103  * invalidate iterators and references.
1104  */
1105  iterator
1106  insert(const_iterator __position, value_type&& __x)
1107  { return emplace(__position, std::move(__x)); }
1108 
1109  /**
1110  * @brief Inserts the contents of an initializer_list into %list
1111  * before specified const_iterator.
1112  * @param __p A const_iterator into the %list.
1113  * @param __l An initializer_list of value_type.
1114  * @return An iterator pointing to the first element inserted
1115  * (or __position).
1116  *
1117  * This function will insert copies of the data in the
1118  * initializer_list @a l into the %list before the location
1119  * specified by @a p.
1120  *
1121  * This operation is linear in the number of elements inserted and
1122  * does not invalidate iterators and references.
1123  */
1124  iterator
1126  { return this->insert(__p, __l.begin(), __l.end()); }
1127 #endif
1128 
1129 #if __cplusplus >= 201103L
1130  /**
1131  * @brief Inserts a number of copies of given data into the %list.
1132  * @param __position A const_iterator into the %list.
1133  * @param __n Number of elements to be inserted.
1134  * @param __x Data to be inserted.
1135  * @return An iterator pointing to the first element inserted
1136  * (or __position).
1137  *
1138  * This function will insert a specified number of copies of the
1139  * given data before the location specified by @a position.
1140  *
1141  * This operation is linear in the number of elements inserted and
1142  * does not invalidate iterators and references.
1143  */
1144  iterator
1145  insert(const_iterator __position, size_type __n, const value_type& __x);
1146 #else
1147  /**
1148  * @brief Inserts a number of copies of given data into the %list.
1149  * @param __position An iterator into the %list.
1150  * @param __n Number of elements to be inserted.
1151  * @param __x Data to be inserted.
1152  *
1153  * This function will insert a specified number of copies of the
1154  * given data before the location specified by @a position.
1155  *
1156  * This operation is linear in the number of elements inserted and
1157  * does not invalidate iterators and references.
1158  */
1159  void
1160  insert(iterator __position, size_type __n, const value_type& __x)
1161  {
1162  list __tmp(__n, __x, get_allocator());
1163  splice(__position, __tmp);
1164  }
1165 #endif
1166 
1167 #if __cplusplus >= 201103L
1168  /**
1169  * @brief Inserts a range into the %list.
1170  * @param __position A const_iterator into the %list.
1171  * @param __first An input iterator.
1172  * @param __last An input iterator.
1173  * @return An iterator pointing to the first element inserted
1174  * (or __position).
1175  *
1176  * This function will insert copies of the data in the range [@a
1177  * first,@a last) into the %list before the location specified by
1178  * @a position.
1179  *
1180  * This operation is linear in the number of elements inserted and
1181  * does not invalidate iterators and references.
1182  */
1183  template<typename _InputIterator,
1184  typename = std::_RequireInputIter<_InputIterator>>
1185  iterator
1186  insert(const_iterator __position, _InputIterator __first,
1187  _InputIterator __last);
1188 #else
1189  /**
1190  * @brief Inserts a range into the %list.
1191  * @param __position An iterator into the %list.
1192  * @param __first An input iterator.
1193  * @param __last An input iterator.
1194  *
1195  * This function will insert copies of the data in the range [@a
1196  * first,@a last) into the %list before the location specified by
1197  * @a position.
1198  *
1199  * This operation is linear in the number of elements inserted and
1200  * does not invalidate iterators and references.
1201  */
1202  template<typename _InputIterator>
1203  void
1204  insert(iterator __position, _InputIterator __first,
1205  _InputIterator __last)
1206  {
1207  list __tmp(__first, __last, get_allocator());
1208  splice(__position, __tmp);
1209  }
1210 #endif
1211 
1212  /**
1213  * @brief Remove element at given position.
1214  * @param __position Iterator pointing to element to be erased.
1215  * @return An iterator pointing to the next element (or end()).
1216  *
1217  * This function will erase the element at the given position and thus
1218  * shorten the %list by one.
1219  *
1220  * Due to the nature of a %list this operation can be done in
1221  * constant time, and only invalidates iterators/references to
1222  * the element being removed. The user is also cautioned that
1223  * this function only erases the element, and that if the element
1224  * is itself a pointer, the pointed-to memory is not touched in
1225  * any way. Managing the pointer is the user's responsibility.
1226  */
1227  iterator
1228 #if __cplusplus >= 201103L
1229  erase(const_iterator __position) noexcept;
1230 #else
1231  erase(iterator __position);
1232 #endif
1233 
1234  /**
1235  * @brief Remove a range of elements.
1236  * @param __first Iterator pointing to the first element to be erased.
1237  * @param __last Iterator pointing to one past the last element to be
1238  * erased.
1239  * @return An iterator pointing to the element pointed to by @a last
1240  * prior to erasing (or end()).
1241  *
1242  * This function will erase the elements in the range @a
1243  * [first,last) and shorten the %list accordingly.
1244  *
1245  * This operation is linear time in the size of the range and only
1246  * invalidates iterators/references to the element being removed.
1247  * The user is also cautioned that this function only erases the
1248  * elements, and that if the elements themselves are pointers, the
1249  * pointed-to memory is not touched in any way. Managing the pointer
1250  * is the user's responsibility.
1251  */
1252  iterator
1253 #if __cplusplus >= 201103L
1254  erase(const_iterator __first, const_iterator __last) noexcept
1255 #else
1256  erase(iterator __first, iterator __last)
1257 #endif
1258  {
1259  while (__first != __last)
1260  __first = erase(__first);
1261  return __last._M_const_cast();
1262  }
1263 
1264  /**
1265  * @brief Swaps data with another %list.
1266  * @param __x A %list of the same element and allocator types.
1267  *
1268  * This exchanges the elements between two lists in constant
1269  * time. Note that the global std::swap() function is
1270  * specialized such that std::swap(l1,l2) will feed to this
1271  * function.
1272  */
1273  void
1274  swap(list& __x)
1275  {
1276  __detail::_List_node_base::swap(this->_M_impl._M_node,
1277  __x._M_impl._M_node);
1278 
1279  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1280  // 431. Swapping containers with unequal allocators.
1281  std::__alloc_swap<typename _Base::_Node_alloc_type>::
1282  _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator());
1283  }
1284 
1285  /**
1286  * Erases all the elements. Note that this function only erases
1287  * the elements, and that if the elements themselves are
1288  * pointers, the pointed-to memory is not touched in any way.
1289  * Managing the pointer is the user's responsibility.
1290  */
1291  void
1292  clear() _GLIBCXX_NOEXCEPT
1293  {
1294  _Base::_M_clear();
1295  _Base::_M_init();
1296  }
1297 
1298  // [23.2.2.4] list operations
1299  /**
1300  * @brief Insert contents of another %list.
1301  * @param __position Iterator referencing the element to insert before.
1302  * @param __x Source list.
1303  *
1304  * The elements of @a __x are inserted in constant time in front of
1305  * the element referenced by @a __position. @a __x becomes an empty
1306  * list.
1307  *
1308  * Requires this != @a __x.
1309  */
1310  void
1311 #if __cplusplus >= 201103L
1312  splice(const_iterator __position, list&& __x) noexcept
1313 #else
1314  splice(iterator __position, list& __x)
1315 #endif
1316  {
1317  if (!__x.empty())
1318  {
1319  _M_check_equal_allocators(__x);
1320 
1321  this->_M_transfer(__position._M_const_cast(),
1322  __x.begin(), __x.end());
1323  }
1324  }
1325 
1326 #if __cplusplus >= 201103L
1327  void
1328  splice(const_iterator __position, list& __x) noexcept
1329  { splice(__position, std::move(__x)); }
1330 #endif
1331 
1332 #if __cplusplus >= 201103L
1333  /**
1334  * @brief Insert element from another %list.
1335  * @param __position Const_iterator referencing the element to
1336  * insert before.
1337  * @param __x Source list.
1338  * @param __i Const_iterator referencing the element to move.
1339  *
1340  * Removes the element in list @a __x referenced by @a __i and
1341  * inserts it into the current list before @a __position.
1342  */
1343  void
1344  splice(const_iterator __position, list&& __x, const_iterator __i) noexcept
1345 #else
1346  /**
1347  * @brief Insert element from another %list.
1348  * @param __position Iterator referencing the element to insert before.
1349  * @param __x Source list.
1350  * @param __i Iterator referencing the element to move.
1351  *
1352  * Removes the element in list @a __x referenced by @a __i and
1353  * inserts it into the current list before @a __position.
1354  */
1355  void
1356  splice(iterator __position, list& __x, iterator __i)
1357 #endif
1358  {
1359  iterator __j = __i._M_const_cast();
1360  ++__j;
1361  if (__position == __i || __position == __j)
1362  return;
1363 
1364  if (this != &__x)
1365  _M_check_equal_allocators(__x);
1366 
1367  this->_M_transfer(__position._M_const_cast(),
1368  __i._M_const_cast(), __j);
1369  }
1370 
1371 #if __cplusplus >= 201103L
1372  /**
1373  * @brief Insert element from another %list.
1374  * @param __position Const_iterator referencing the element to
1375  * insert before.
1376  * @param __x Source list.
1377  * @param __i Const_iterator referencing the element to move.
1378  *
1379  * Removes the element in list @a __x referenced by @a __i and
1380  * inserts it into the current list before @a __position.
1381  */
1382  void
1383  splice(const_iterator __position, list& __x, const_iterator __i) noexcept
1384  { splice(__position, std::move(__x), __i); }
1385 #endif
1386 
1387 #if __cplusplus >= 201103L
1388  /**
1389  * @brief Insert range from another %list.
1390  * @param __position Const_iterator referencing the element to
1391  * insert before.
1392  * @param __x Source list.
1393  * @param __first Const_iterator referencing the start of range in x.
1394  * @param __last Const_iterator referencing the end of range in x.
1395  *
1396  * Removes elements in the range [__first,__last) and inserts them
1397  * before @a __position in constant time.
1398  *
1399  * Undefined if @a __position is in [__first,__last).
1400  */
1401  void
1402  splice(const_iterator __position, list&& __x, const_iterator __first,
1403  const_iterator __last) noexcept
1404 #else
1405  /**
1406  * @brief Insert range from another %list.
1407  * @param __position Iterator referencing the element to insert before.
1408  * @param __x Source list.
1409  * @param __first Iterator referencing the start of range in x.
1410  * @param __last Iterator referencing the end of range in x.
1411  *
1412  * Removes elements in the range [__first,__last) and inserts them
1413  * before @a __position in constant time.
1414  *
1415  * Undefined if @a __position is in [__first,__last).
1416  */
1417  void
1418  splice(iterator __position, list& __x, iterator __first,
1419  iterator __last)
1420 #endif
1421  {
1422  if (__first != __last)
1423  {
1424  if (this != &__x)
1425  _M_check_equal_allocators(__x);
1426 
1427  this->_M_transfer(__position._M_const_cast(),
1428  __first._M_const_cast(),
1429  __last._M_const_cast());
1430  }
1431  }
1432 
1433 #if __cplusplus >= 201103L
1434  /**
1435  * @brief Insert range from another %list.
1436  * @param __position Const_iterator referencing the element to
1437  * insert before.
1438  * @param __x Source list.
1439  * @param __first Const_iterator referencing the start of range in x.
1440  * @param __last Const_iterator referencing the end of range in x.
1441  *
1442  * Removes elements in the range [__first,__last) and inserts them
1443  * before @a __position in constant time.
1444  *
1445  * Undefined if @a __position is in [__first,__last).
1446  */
1447  void
1448  splice(const_iterator __position, list& __x, const_iterator __first,
1449  const_iterator __last) noexcept
1450  { splice(__position, std::move(__x), __first, __last); }
1451 #endif
1452 
1453  /**
1454  * @brief Remove all elements equal to value.
1455  * @param __value The value to remove.
1456  *
1457  * Removes every element in the list equal to @a value.
1458  * Remaining elements stay in list order. Note that this
1459  * function only erases the elements, and that if the elements
1460  * themselves are pointers, the pointed-to memory is not
1461  * touched in any way. Managing the pointer is the user's
1462  * responsibility.
1463  */
1464  void
1465  remove(const _Tp& __value);
1466 
1467  /**
1468  * @brief Remove all elements satisfying a predicate.
1469  * @tparam _Predicate Unary predicate function or object.
1470  *
1471  * Removes every element in the list for which the predicate
1472  * returns true. Remaining elements stay in list order. Note
1473  * that this function only erases the elements, and that if the
1474  * elements themselves are pointers, the pointed-to memory is
1475  * not touched in any way. Managing the pointer is the user's
1476  * responsibility.
1477  */
1478  template<typename _Predicate>
1479  void
1480  remove_if(_Predicate);
1481 
1482  /**
1483  * @brief Remove consecutive duplicate elements.
1484  *
1485  * For each consecutive set of elements with the same value,
1486  * remove all but the first one. Remaining elements stay in
1487  * list order. Note that this function only erases the
1488  * elements, and that if the elements themselves are pointers,
1489  * the pointed-to memory is not touched in any way. Managing
1490  * the pointer is the user's responsibility.
1491  */
1492  void
1493  unique();
1494 
1495  /**
1496  * @brief Remove consecutive elements satisfying a predicate.
1497  * @tparam _BinaryPredicate Binary predicate function or object.
1498  *
1499  * For each consecutive set of elements [first,last) that
1500  * satisfy predicate(first,i) where i is an iterator in
1501  * [first,last), remove all but the first one. Remaining
1502  * elements stay in list order. Note that this function only
1503  * erases the elements, and that if the elements themselves are
1504  * pointers, the pointed-to memory is not touched in any way.
1505  * Managing the pointer is the user's responsibility.
1506  */
1507  template<typename _BinaryPredicate>
1508  void
1509  unique(_BinaryPredicate);
1510 
1511  /**
1512  * @brief Merge sorted lists.
1513  * @param __x Sorted list to merge.
1514  *
1515  * Assumes that both @a __x and this list are sorted according to
1516  * operator<(). Merges elements of @a __x into this list in
1517  * sorted order, leaving @a __x empty when complete. Elements in
1518  * this list precede elements in @a __x that are equal.
1519  */
1520 #if __cplusplus >= 201103L
1521  void
1522  merge(list&& __x);
1523 
1524  void
1525  merge(list& __x)
1526  { merge(std::move(__x)); }
1527 #else
1528  void
1529  merge(list& __x);
1530 #endif
1531 
1532  /**
1533  * @brief Merge sorted lists according to comparison function.
1534  * @tparam _StrictWeakOrdering Comparison function defining
1535  * sort order.
1536  * @param __x Sorted list to merge.
1537  * @param __comp Comparison functor.
1538  *
1539  * Assumes that both @a __x and this list are sorted according to
1540  * StrictWeakOrdering. Merges elements of @a __x into this list
1541  * in sorted order, leaving @a __x empty when complete. Elements
1542  * in this list precede elements in @a __x that are equivalent
1543  * according to StrictWeakOrdering().
1544  */
1545 #if __cplusplus >= 201103L
1546  template<typename _StrictWeakOrdering>
1547  void
1548  merge(list&& __x, _StrictWeakOrdering __comp);
1549 
1550  template<typename _StrictWeakOrdering>
1551  void
1552  merge(list& __x, _StrictWeakOrdering __comp)
1553  { merge(std::move(__x), __comp); }
1554 #else
1555  template<typename _StrictWeakOrdering>
1556  void
1557  merge(list& __x, _StrictWeakOrdering __comp);
1558 #endif
1559 
1560  /**
1561  * @brief Reverse the elements in list.
1562  *
1563  * Reverse the order of elements in the list in linear time.
1564  */
1565  void
1566  reverse() _GLIBCXX_NOEXCEPT
1567  { this->_M_impl._M_node._M_reverse(); }
1568 
1569  /**
1570  * @brief Sort the elements.
1571  *
1572  * Sorts the elements of this list in NlogN time. Equivalent
1573  * elements remain in list order.
1574  */
1575  void
1576  sort();
1577 
1578  /**
1579  * @brief Sort the elements according to comparison function.
1580  *
1581  * Sorts the elements of this list in NlogN time. Equivalent
1582  * elements remain in list order.
1583  */
1584  template<typename _StrictWeakOrdering>
1585  void
1586  sort(_StrictWeakOrdering);
1587 
1588  protected:
1589  // Internal constructor functions follow.
1590 
1591  // Called by the range constructor to implement [23.1.1]/9
1592 
1593  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1594  // 438. Ambiguity in the "do the right thing" clause
1595  template<typename _Integer>
1596  void
1597  _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1598  { _M_fill_initialize(static_cast<size_type>(__n), __x); }
1599 
1600  // Called by the range constructor to implement [23.1.1]/9
1601  template<typename _InputIterator>
1602  void
1603  _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1604  __false_type)
1605  {
1606  for (; __first != __last; ++__first)
1607 #if __cplusplus >= 201103L
1608  emplace_back(*__first);
1609 #else
1610  push_back(*__first);
1611 #endif
1612  }
1613 
1614  // Called by list(n,v,a), and the range constructor when it turns out
1615  // to be the same thing.
1616  void
1617  _M_fill_initialize(size_type __n, const value_type& __x)
1618  {
1619  for (; __n; --__n)
1620  push_back(__x);
1621  }
1622 
1623 #if __cplusplus >= 201103L
1624  // Called by list(n).
1625  void
1626  _M_default_initialize(size_type __n)
1627  {
1628  for (; __n; --__n)
1629  emplace_back();
1630  }
1631 
1632  // Called by resize(sz).
1633  void
1634  _M_default_append(size_type __n);
1635 #endif
1636 
1637  // Internal assign functions follow.
1638 
1639  // Called by the range assign to implement [23.1.1]/9
1640 
1641  // _GLIBCXX_RESOLVE_LIB_DEFECTS
1642  // 438. Ambiguity in the "do the right thing" clause
1643  template<typename _Integer>
1644  void
1645  _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1646  { _M_fill_assign(__n, __val); }
1647 
1648  // Called by the range assign to implement [23.1.1]/9
1649  template<typename _InputIterator>
1650  void
1651  _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1652  __false_type);
1653 
1654  // Called by assign(n,t), and the range assign when it turns out
1655  // to be the same thing.
1656  void
1657  _M_fill_assign(size_type __n, const value_type& __val);
1658 
1659 
1660  // Moves the elements from [first,last) before position.
1661  void
1662  _M_transfer(iterator __position, iterator __first, iterator __last)
1663  { __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
1664 
1665  // Inserts new element at position given and with value given.
1666 #if __cplusplus < 201103L
1667  void
1668  _M_insert(iterator __position, const value_type& __x)
1669  {
1670  _Node* __tmp = _M_create_node(__x);
1671  __tmp->_M_hook(__position._M_node);
1672  }
1673 #else
1674  template<typename... _Args>
1675  void
1676  _M_insert(iterator __position, _Args&&... __args)
1677  {
1678  _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
1679  __tmp->_M_hook(__position._M_node);
1680  }
1681 #endif
1682 
1683  // Erases element at position given.
1684  void
1685  _M_erase(iterator __position) _GLIBCXX_NOEXCEPT
1686  {
1687  __position._M_node->_M_unhook();
1688  _Node* __n = static_cast<_Node*>(__position._M_node);
1689 #if __cplusplus >= 201103L
1690  _M_get_Node_allocator().destroy(__n);
1691 #else
1692  _M_get_Tp_allocator().destroy(std::__addressof(__n->_M_data));
1693 #endif
1694  _M_put_node(__n);
1695  }
1696 
1697  // To implement the splice (and merge) bits of N1599.
1698  void
1699  _M_check_equal_allocators(list& __x) _GLIBCXX_NOEXCEPT
1700  {
1701  if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
1702  _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
1703  __builtin_abort();
1704  }
1705  };
1706 
1707  /**
1708  * @brief List equality comparison.
1709  * @param __x A %list.
1710  * @param __y A %list of the same type as @a __x.
1711  * @return True iff the size and elements of the lists are equal.
1712  *
1713  * This is an equivalence relation. It is linear in the size of
1714  * the lists. Lists are considered equivalent if their sizes are
1715  * equal, and if corresponding elements compare equal.
1716  */
1717  template<typename _Tp, typename _Alloc>
1718  inline bool
1719  operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1720  {
1721  typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
1722  const_iterator __end1 = __x.end();
1723  const_iterator __end2 = __y.end();
1724 
1725  const_iterator __i1 = __x.begin();
1726  const_iterator __i2 = __y.begin();
1727  while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
1728  {
1729  ++__i1;
1730  ++__i2;
1731  }
1732  return __i1 == __end1 && __i2 == __end2;
1733  }
1734 
1735  /**
1736  * @brief List ordering relation.
1737  * @param __x A %list.
1738  * @param __y A %list of the same type as @a __x.
1739  * @return True iff @a __x is lexicographically less than @a __y.
1740  *
1741  * This is a total ordering relation. It is linear in the size of the
1742  * lists. The elements must be comparable with @c <.
1743  *
1744  * See std::lexicographical_compare() for how the determination is made.
1745  */
1746  template<typename _Tp, typename _Alloc>
1747  inline bool
1748  operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1749  { return std::lexicographical_compare(__x.begin(), __x.end(),
1750  __y.begin(), __y.end()); }
1751 
1752  /// Based on operator==
1753  template<typename _Tp, typename _Alloc>
1754  inline bool
1755  operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1756  { return !(__x == __y); }
1757 
1758  /// Based on operator<
1759  template<typename _Tp, typename _Alloc>
1760  inline bool
1761  operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1762  { return __y < __x; }
1763 
1764  /// Based on operator<
1765  template<typename _Tp, typename _Alloc>
1766  inline bool
1767  operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1768  { return !(__y < __x); }
1769 
1770  /// Based on operator<
1771  template<typename _Tp, typename _Alloc>
1772  inline bool
1773  operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1774  { return !(__x < __y); }
1775 
1776  /// See std::list::swap().
1777  template<typename _Tp, typename _Alloc>
1778  inline void
1780  { __x.swap(__y); }
1781 
1782 _GLIBCXX_END_NAMESPACE_CONTAINER
1783 } // namespace std
1784 
1785 #endif /* _STL_LIST_H */
void sort()
Sort the elements.
Definition: list.tcc:396
const_reverse_iterator crend() const noexcept
Definition: stl_list.h:861
void remove_if(_Predicate)
Remove all elements satisfying a predicate.
Definition: list.tcc:434
reverse_iterator rbegin() noexcept
Definition: stl_list.h:797
list(const allocator_type &__a=allocator_type()) noexcept
Creates a list with no elements.
Definition: stl_list.h:534
list(const list &__x)
List copy constructor.
Definition: stl_list.h:585
void assign(size_type __n, const value_type &__val)
Assigns a given value to a list.
Definition: stl_list.h:705
iterator erase(const_iterator __position) noexcept
Remove element at given position.
Definition: list.tcc:148
list & operator=(list &&__x)
List move assignment operator.
Definition: stl_list.h:670
size_type max_size() const noexcept
Definition: stl_list.h:881
list(size_type __n, const value_type &__value, const allocator_type &__a=allocator_type())
Creates a list with copies of an exemplar element.
Definition: stl_list.h:558
iterator end() noexcept
Definition: stl_list.h:779
void splice(const_iterator __position, list &&__x, const_iterator __i) noexcept
Insert element from another list.
Definition: stl_list.h:1344
void splice(const_iterator __position, list &&__x) noexcept
Insert contents of another list.
Definition: stl_list.h:1312
_Tp _M_data
&lt; User&#39;s data.
Definition: stl_list.h:109
void pop_front() noexcept
Removes first element.
Definition: stl_list.h:1004
const_reverse_iterator crbegin() const noexcept
Definition: stl_list.h:852
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
Definition: stl_list.h:447
A list::iterator.
Definition: stl_list.h:125
const_reverse_iterator rend() const noexcept
Definition: stl_list.h:824
const_iterator end() const noexcept
Definition: stl_list.h:788
void assign(initializer_list< value_type > __l)
Assigns an initializer_list to a list.
Definition: stl_list.h:746
list & operator=(initializer_list< value_type > __l)
List initializer list assignment operator.
Definition: stl_list.h:687
const_reference front() const noexcept
Definition: stl_list.h:938
list(initializer_list< value_type > __l, const allocator_type &__a=allocator_type())
Builds a list from an initializer_list.
Definition: stl_list.h:608
iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Definition: stl_list.h:752
An actual node in the list.
Definition: stl_list.h:106
void resize(size_type __new_size)
Resizes the list to the specified number of elements.
Definition: list.tcc:181
A list::const_iterator.
Definition: stl_list.h:204
iterator erase(const_iterator __first, const_iterator __last) noexcept
Remove a range of elements.
Definition: stl_list.h:1254
void push_front(const value_type &__x)
Add data to the front of the list.
Definition: stl_list.h:977
Common part of a node in the list.
Definition: stl_list.h:77
void push_back(const value_type &__x)
Add data to the end of the list.
Definition: stl_list.h:1018
void merge(list &&__x)
Merge sorted lists.
iterator insert(const_iterator __p, initializer_list< value_type > __l)
Inserts the contents of an initializer_list into list before specified const_iterator.
Definition: stl_list.h:1125
reverse_iterator rend() noexcept
Definition: stl_list.h:815
See bits/stl_deque.h&#39;s _Deque_base for an explanation.
Definition: stl_list.h:298
const_iterator begin() const noexcept
Definition: stl_list.h:770
void splice(const_iterator __position, list &__x, const_iterator __first, const_iterator __last) noexcept
Insert range from another list.
Definition: stl_list.h:1448
void pop_back() noexcept
Removes last element.
Definition: stl_list.h:1044
list(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Builds a list from a range.
Definition: stl_list.h:627
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition: move.h:76
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a list.
Definition: stl_list.h:724
Bidirectional iterators support a superset of forward iterator operations.
list & operator=(const list &__x)
List assignment operator.
Definition: list.tcc:227
iterator emplace(const_iterator __position, _Args &&...__args)
Constructs object in list before specified iterator.
const_iterator cend() const noexcept
Definition: stl_list.h:843
const_reference back() const noexcept
Definition: stl_list.h:958
iterator insert(const_iterator __position, value_type &&__x)
Inserts given rvalue into list before specified iterator.
Definition: stl_list.h:1106
void clear() noexcept
Definition: stl_list.h:1292
size_type size() const noexcept
Definition: stl_list.h:876
bool empty() const noexcept
Definition: stl_list.h:871
void reverse() noexcept
Reverse the elements in list.
Definition: stl_list.h:1566
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
Definition: functional:2534
Common iterator class.
iterator begin() noexcept
Definition: stl_list.h:761
const_iterator cbegin() const noexcept
Definition: stl_list.h:834
initializer_list
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition: move.h:47
void unique()
Remove consecutive duplicate elements.
Definition: list.tcc:309
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
const_reverse_iterator rbegin() const noexcept
Definition: stl_list.h:806
void swap(list &__x)
Swaps data with another list.
Definition: stl_list.h:1274
list(list &&__x) noexcept
List move constructor.
Definition: stl_list.h:597
list(size_type __n)
Creates a list with default constructed elements.
Definition: stl_list.h:546
_Node * _M_create_node(_Args &&...__args)
Definition: stl_list.h:509
void splice(const_iterator __position, list &__x, const_iterator __i) noexcept
Insert element from another list.
Definition: stl_list.h:1383
reference back() noexcept
Definition: stl_list.h:946
reference front() noexcept
Definition: stl_list.h:930
void splice(const_iterator __position, list &&__x, const_iterator __first, const_iterator __last) noexcept
Insert range from another list.
Definition: stl_list.h:1402
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into list before specified iterator.