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