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