OSDN Git Service

2010-05-20 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.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       /**
512        *  @brief  Creates a %list with copies of an exemplar element.
513        *  @param  n  The number of elements to initially create.
514        *  @param  value  An element to copy.
515        *  @param  a  An allocator object.
516        *
517        *  This constructor fills the %list with @a n copies of @a value.
518        */
519       explicit
520       list(size_type __n, const value_type& __value = value_type(),
521            const allocator_type& __a = allocator_type())
522       : _Base(__a)
523       { _M_fill_initialize(__n, __value); }
524
525       /**
526        *  @brief  %List copy constructor.
527        *  @param  x  A %list of identical element and allocator types.
528        *
529        *  The newly-created %list uses a copy of the allocation object used
530        *  by @a x.
531        */
532       list(const list& __x)
533       : _Base(__x._M_get_Node_allocator())
534       { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
535
536 #ifdef __GXX_EXPERIMENTAL_CXX0X__
537       /**
538        *  @brief  %List move constructor.
539        *  @param  x  A %list of identical element and allocator types.
540        *
541        *  The newly-created %list contains the exact contents of @a x.
542        *  The contents of @a x are a valid, but unspecified %list.
543        */
544       list(list&& __x)
545       : _Base(std::forward<_Base>(__x)) { }
546
547       /**
548        *  @brief  Builds a %list from an initializer_list
549        *  @param  l  An initializer_list of value_type.
550        *  @param  a  An allocator object.
551        *
552        *  Create a %list consisting of copies of the elements in the
553        *  initializer_list @a l.  This is linear in l.size().
554        */
555       list(initializer_list<value_type> __l,
556            const allocator_type& __a = allocator_type())
557       : _Base(__a)
558       { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); }
559 #endif
560
561       /**
562        *  @brief  Builds a %list from a range.
563        *  @param  first  An input iterator.
564        *  @param  last  An input iterator.
565        *  @param  a  An allocator object.
566        *
567        *  Create a %list consisting of copies of the elements from
568        *  [@a first,@a last).  This is linear in N (where N is
569        *  distance(@a first,@a last)).
570        */
571       template<typename _InputIterator>
572         list(_InputIterator __first, _InputIterator __last,
573              const allocator_type& __a = allocator_type())
574         : _Base(__a)
575         { 
576           // Check whether it's an integral type.  If so, it's not an iterator.
577           typedef typename std::__is_integer<_InputIterator>::__type _Integral;
578           _M_initialize_dispatch(__first, __last, _Integral());
579         }
580
581       /**
582        *  No explicit dtor needed as the _Base dtor takes care of
583        *  things.  The _Base dtor only erases the elements, and note
584        *  that if the elements themselves are pointers, the pointed-to
585        *  memory is not touched in any way.  Managing the pointer is
586        *  the user's responsibility.
587        */
588
589       /**
590        *  @brief  %List assignment operator.
591        *  @param  x  A %list of identical element and allocator types.
592        *
593        *  All the elements of @a x are copied, but unlike the copy
594        *  constructor, the allocator object is not copied.
595        */
596       list&
597       operator=(const list& __x);
598
599 #ifdef __GXX_EXPERIMENTAL_CXX0X__
600       /**
601        *  @brief  %List move assignment operator.
602        *  @param  x  A %list of identical element and allocator types.
603        *
604        *  The contents of @a x are moved into this %list (without copying).
605        *  @a x is a valid, but unspecified %list
606        */
607       list&
608       operator=(list&& __x)
609       {
610         // NB: DR 1204.
611         // NB: DR 675.
612         this->clear();
613         this->swap(__x);
614         return *this;
615       }
616
617       /**
618        *  @brief  %List initializer list assignment operator.
619        *  @param  l  An initializer_list of value_type.
620        *
621        *  Replace the contents of the %list with copies of the elements
622        *  in the initializer_list @a l.  This is linear in l.size().
623        */
624       list&
625       operator=(initializer_list<value_type> __l)
626       {
627         this->assign(__l.begin(), __l.end());
628         return *this;
629       }
630 #endif
631
632       /**
633        *  @brief  Assigns a given value to a %list.
634        *  @param  n  Number of elements to be assigned.
635        *  @param  val  Value to be assigned.
636        *
637        *  This function fills a %list with @a n copies of the given
638        *  value.  Note that the assignment completely changes the %list
639        *  and that the resulting %list's size is the same as the number
640        *  of elements assigned.  Old data may be lost.
641        */
642       void
643       assign(size_type __n, const value_type& __val)
644       { _M_fill_assign(__n, __val); }
645
646       /**
647        *  @brief  Assigns a range to a %list.
648        *  @param  first  An input iterator.
649        *  @param  last   An input iterator.
650        *
651        *  This function fills a %list with copies of the elements in the
652        *  range [@a first,@a last).
653        *
654        *  Note that the assignment completely changes the %list and
655        *  that the resulting %list's size is the same as the number of
656        *  elements assigned.  Old data may be lost.
657        */
658       template<typename _InputIterator>
659         void
660         assign(_InputIterator __first, _InputIterator __last)
661         {
662           // Check whether it's an integral type.  If so, it's not an iterator.
663           typedef typename std::__is_integer<_InputIterator>::__type _Integral;
664           _M_assign_dispatch(__first, __last, _Integral());
665         }
666
667 #ifdef __GXX_EXPERIMENTAL_CXX0X__
668       /**
669        *  @brief  Assigns an initializer_list to a %list.
670        *  @param  l  An initializer_list of value_type.
671        *
672        *  Replace the contents of the %list with copies of the elements
673        *  in the initializer_list @a l.  This is linear in l.size().
674        */
675       void
676       assign(initializer_list<value_type> __l)
677       { this->assign(__l.begin(), __l.end()); }
678 #endif
679
680       /// Get a copy of the memory allocation object.
681       allocator_type
682       get_allocator() const
683       { return _Base::get_allocator(); }
684
685       // iterators
686       /**
687        *  Returns a read/write iterator that points to the first element in the
688        *  %list.  Iteration is done in ordinary element order.
689        */
690       iterator
691       begin()
692       { return iterator(this->_M_impl._M_node._M_next); }
693
694       /**
695        *  Returns a read-only (constant) iterator that points to the
696        *  first element in the %list.  Iteration is done in ordinary
697        *  element order.
698        */
699       const_iterator
700       begin() const
701       { return const_iterator(this->_M_impl._M_node._M_next); }
702
703       /**
704        *  Returns a read/write iterator that points one past the last
705        *  element in the %list.  Iteration is done in ordinary element
706        *  order.
707        */
708       iterator
709       end()
710       { return iterator(&this->_M_impl._M_node); }
711
712       /**
713        *  Returns a read-only (constant) iterator that points one past
714        *  the last element in the %list.  Iteration is done in ordinary
715        *  element order.
716        */
717       const_iterator
718       end() const
719       { return const_iterator(&this->_M_impl._M_node); }
720
721       /**
722        *  Returns a read/write reverse iterator that points to the last
723        *  element in the %list.  Iteration is done in reverse element
724        *  order.
725        */
726       reverse_iterator
727       rbegin()
728       { return reverse_iterator(end()); }
729
730       /**
731        *  Returns a read-only (constant) reverse iterator that points to
732        *  the last element in the %list.  Iteration is done in reverse
733        *  element order.
734        */
735       const_reverse_iterator
736       rbegin() const
737       { return const_reverse_iterator(end()); }
738
739       /**
740        *  Returns a read/write reverse iterator that points to one
741        *  before the first element in the %list.  Iteration is done in
742        *  reverse element order.
743        */
744       reverse_iterator
745       rend()
746       { return reverse_iterator(begin()); }
747
748       /**
749        *  Returns a read-only (constant) reverse iterator that points to one
750        *  before the first element in the %list.  Iteration is done in reverse
751        *  element order.
752        */
753       const_reverse_iterator
754       rend() const
755       { return const_reverse_iterator(begin()); }
756
757 #ifdef __GXX_EXPERIMENTAL_CXX0X__
758       /**
759        *  Returns a read-only (constant) iterator that points to the
760        *  first element in the %list.  Iteration is done in ordinary
761        *  element order.
762        */
763       const_iterator
764       cbegin() const
765       { return const_iterator(this->_M_impl._M_node._M_next); }
766
767       /**
768        *  Returns a read-only (constant) iterator that points one past
769        *  the last element in the %list.  Iteration is done in ordinary
770        *  element order.
771        */
772       const_iterator
773       cend() const
774       { return const_iterator(&this->_M_impl._M_node); }
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       crbegin() const
783       { return const_reverse_iterator(end()); }
784
785       /**
786        *  Returns a read-only (constant) reverse iterator that points to one
787        *  before the first element in the %list.  Iteration is done in reverse
788        *  element order.
789        */
790       const_reverse_iterator
791       crend() const
792       { return const_reverse_iterator(begin()); }
793 #endif
794
795       // [23.2.2.2] capacity
796       /**
797        *  Returns true if the %list is empty.  (Thus begin() would equal
798        *  end().)
799        */
800       bool
801       empty() const
802       { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
803
804       /**  Returns the number of elements in the %list.  */
805       size_type
806       size() const
807       { return std::distance(begin(), end()); }
808
809       /**  Returns the size() of the largest possible %list.  */
810       size_type
811       max_size() const
812       { return _M_get_Node_allocator().max_size(); }
813
814       /**
815        *  @brief Resizes the %list to the specified number of elements.
816        *  @param new_size Number of elements the %list should contain.
817        *  @param x Data with which new elements should be populated.
818        *
819        *  This function will %resize the %list to the specified number
820        *  of elements.  If the number is smaller than the %list's
821        *  current size the %list is truncated, otherwise the %list is
822        *  extended and new elements are populated with given data.
823        */
824       void
825       resize(size_type __new_size, value_type __x = value_type());
826
827       // element access
828       /**
829        *  Returns a read/write reference to the data at the first
830        *  element of the %list.
831        */
832       reference
833       front()
834       { return *begin(); }
835
836       /**
837        *  Returns a read-only (constant) reference to the data at the first
838        *  element of the %list.
839        */
840       const_reference
841       front() const
842       { return *begin(); }
843
844       /**
845        *  Returns a read/write reference to the data at the last element
846        *  of the %list.
847        */
848       reference
849       back()
850       { 
851         iterator __tmp = end();
852         --__tmp;
853         return *__tmp;
854       }
855
856       /**
857        *  Returns a read-only (constant) reference to the data at the last
858        *  element of the %list.
859        */
860       const_reference
861       back() const
862       { 
863         const_iterator __tmp = end();
864         --__tmp;
865         return *__tmp;
866       }
867
868       // [23.2.2.3] modifiers
869       /**
870        *  @brief  Add data to the front of the %list.
871        *  @param  x  Data to be added.
872        *
873        *  This is a typical stack operation.  The function creates an
874        *  element at the front of the %list and assigns the given data
875        *  to it.  Due to the nature of a %list this operation can be
876        *  done in constant time, and does not invalidate iterators and
877        *  references.
878        */
879       void
880       push_front(const value_type& __x)
881       { this->_M_insert(begin(), __x); }
882
883 #ifdef __GXX_EXPERIMENTAL_CXX0X__
884       void
885       push_front(value_type&& __x)
886       { this->_M_insert(begin(), std::move(__x)); }
887
888       template<typename... _Args>
889         void
890         emplace_front(_Args&&... __args)
891         { this->_M_insert(begin(), std::forward<_Args>(__args)...); }
892 #endif
893
894       /**
895        *  @brief  Removes first element.
896        *
897        *  This is a typical stack operation.  It shrinks the %list by
898        *  one.  Due to the nature of a %list this operation can be done
899        *  in constant time, and only invalidates iterators/references to
900        *  the element being removed.
901        *
902        *  Note that no data is returned, and if the first element's data
903        *  is needed, it should be retrieved before pop_front() is
904        *  called.
905        */
906       void
907       pop_front()
908       { this->_M_erase(begin()); }
909
910       /**
911        *  @brief  Add data to the end of the %list.
912        *  @param  x  Data to be added.
913        *
914        *  This is a typical stack operation.  The function creates an
915        *  element at the end of the %list and assigns the given data to
916        *  it.  Due to the nature of a %list this operation can be done
917        *  in constant time, and does not invalidate iterators and
918        *  references.
919        */
920       void
921       push_back(const value_type& __x)
922       { this->_M_insert(end(), __x); }
923
924 #ifdef __GXX_EXPERIMENTAL_CXX0X__
925       void
926       push_back(value_type&& __x)
927       { this->_M_insert(end(), std::move(__x)); }
928
929       template<typename... _Args>
930         void
931         emplace_back(_Args&&... __args)
932         { this->_M_insert(end(), std::forward<_Args>(__args)...); }
933 #endif
934
935       /**
936        *  @brief  Removes last element.
937        *
938        *  This is a typical stack operation.  It shrinks the %list by
939        *  one.  Due to the nature of a %list this operation can be done
940        *  in constant time, and only invalidates iterators/references to
941        *  the element being removed.
942        *
943        *  Note that no data is returned, and if the last element's data
944        *  is needed, it should be retrieved before pop_back() is called.
945        */
946       void
947       pop_back()
948       { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
949
950 #ifdef __GXX_EXPERIMENTAL_CXX0X__
951       /**
952        *  @brief  Constructs object in %list before specified iterator.
953        *  @param  position  A const_iterator into the %list.
954        *  @param  args  Arguments.
955        *  @return  An iterator that points to the inserted data.
956        *
957        *  This function will insert an object of type T constructed
958        *  with T(std::forward<Args>(args)...) before the specified
959        *  location.  Due to the nature of a %list this operation can
960        *  be done in constant time, and does not invalidate iterators
961        *  and references.
962        */
963       template<typename... _Args>
964         iterator
965         emplace(iterator __position, _Args&&... __args);
966 #endif
967
968       /**
969        *  @brief  Inserts given value into %list before specified iterator.
970        *  @param  position  An iterator into the %list.
971        *  @param  x  Data to be inserted.
972        *  @return  An iterator that points to the inserted data.
973        *
974        *  This function will insert a copy of the given value before
975        *  the specified location.  Due to the nature of a %list this
976        *  operation can be done in constant time, and does not
977        *  invalidate iterators and references.
978        */
979       iterator
980       insert(iterator __position, const value_type& __x);
981
982 #ifdef __GXX_EXPERIMENTAL_CXX0X__
983       /**
984        *  @brief  Inserts given rvalue into %list before specified iterator.
985        *  @param  position  An iterator into the %list.
986        *  @param  x  Data to be inserted.
987        *  @return  An iterator that points to the inserted data.
988        *
989        *  This function will insert a copy of the given rvalue before
990        *  the specified location.  Due to the nature of a %list this
991        *  operation can be done in constant time, and does not
992        *  invalidate iterators and references.
993         */
994       iterator
995       insert(iterator __position, value_type&& __x)
996       { return emplace(__position, std::move(__x)); }
997
998       /**
999        *  @brief  Inserts the contents of an initializer_list into %list
1000        *          before specified iterator.
1001        *  @param  p  An iterator into the %list.
1002        *  @param  l  An initializer_list of value_type.
1003        *
1004        *  This function will insert copies of the data in the
1005        *  initializer_list @a l into the %list before the location
1006        *  specified by @a p.
1007        *
1008        *  This operation is linear in the number of elements inserted and
1009        *  does not invalidate iterators and references.
1010        */
1011       void
1012       insert(iterator __p, initializer_list<value_type> __l)
1013       { this->insert(__p, __l.begin(), __l.end()); }
1014 #endif
1015
1016       /**
1017        *  @brief  Inserts a number of copies of given data into the %list.
1018        *  @param  position  An iterator into the %list.
1019        *  @param  n  Number of elements to be inserted.
1020        *  @param  x  Data to be inserted.
1021        *
1022        *  This function will insert a specified number of copies of the
1023        *  given data before the location specified by @a position.
1024        *
1025        *  This operation is linear in the number of elements inserted and
1026        *  does not invalidate iterators and references.
1027        */
1028       void
1029       insert(iterator __position, size_type __n, const value_type& __x)
1030       {  
1031         list __tmp(__n, __x, _M_get_Node_allocator());
1032         splice(__position, __tmp);
1033       }
1034
1035       /**
1036        *  @brief  Inserts a range into the %list.
1037        *  @param  position  An iterator into the %list.
1038        *  @param  first  An input iterator.
1039        *  @param  last   An input iterator.
1040        *
1041        *  This function will insert copies of the data in the range [@a
1042        *  first,@a last) into the %list before the location specified by
1043        *  @a position.
1044        *
1045        *  This operation is linear in the number of elements inserted and
1046        *  does not invalidate iterators and references.
1047        */
1048       template<typename _InputIterator>
1049         void
1050         insert(iterator __position, _InputIterator __first,
1051                _InputIterator __last)
1052         {
1053           list __tmp(__first, __last, _M_get_Node_allocator());
1054           splice(__position, __tmp);
1055         }
1056
1057       /**
1058        *  @brief  Remove element at given position.
1059        *  @param  position  Iterator pointing to element to be erased.
1060        *  @return  An iterator pointing to the next element (or end()).
1061        *
1062        *  This function will erase the element at the given position and thus
1063        *  shorten the %list by one.
1064        *
1065        *  Due to the nature of a %list this operation can be done in
1066        *  constant time, and only invalidates iterators/references to
1067        *  the element being removed.  The user is also cautioned that
1068        *  this function only erases the element, and that if the element
1069        *  is itself a pointer, the pointed-to memory is not touched in
1070        *  any way.  Managing the pointer is the user's responsibility.
1071        */
1072       iterator
1073       erase(iterator __position);
1074
1075       /**
1076        *  @brief  Remove a range of elements.
1077        *  @param  first  Iterator pointing to the first element to be erased.
1078        *  @param  last  Iterator pointing to one past the last element to be
1079        *                erased.
1080        *  @return  An iterator pointing to the element pointed to by @a last
1081        *           prior to erasing (or end()).
1082        *
1083        *  This function will erase the elements in the range @a
1084        *  [first,last) and shorten the %list accordingly.
1085        *
1086        *  This operation is linear time in the size of the range and only
1087        *  invalidates iterators/references to the element being removed.
1088        *  The user is also cautioned that this function only erases the
1089        *  elements, and that if the elements themselves are pointers, the
1090        *  pointed-to memory is not touched in any way.  Managing the pointer
1091        *  is the user's responsibility.
1092        */
1093       iterator
1094       erase(iterator __first, iterator __last)
1095       {
1096         while (__first != __last)
1097           __first = erase(__first);
1098         return __last;
1099       }
1100
1101       /**
1102        *  @brief  Swaps data with another %list.
1103        *  @param  x  A %list of the same element and allocator types.
1104        *
1105        *  This exchanges the elements between two lists in constant
1106        *  time.  Note that the global std::swap() function is
1107        *  specialized such that std::swap(l1,l2) will feed to this
1108        *  function.
1109        */
1110       void
1111       swap(list& __x)
1112       {
1113         _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node);
1114
1115         // _GLIBCXX_RESOLVE_LIB_DEFECTS
1116         // 431. Swapping containers with unequal allocators.
1117         std::__alloc_swap<typename _Base::_Node_alloc_type>::
1118           _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator());
1119       }
1120
1121       /**
1122        *  Erases all the elements.  Note that this function only erases
1123        *  the elements, and that if the elements themselves are
1124        *  pointers, the pointed-to memory is not touched in any way.
1125        *  Managing the pointer is the user's responsibility.
1126        */
1127       void
1128       clear()
1129       {
1130         _Base::_M_clear();
1131         _Base::_M_init();
1132       }
1133
1134       // [23.2.2.4] list operations
1135       /**
1136        *  @brief  Insert contents of another %list.
1137        *  @param  position  Iterator referencing the element to insert before.
1138        *  @param  x  Source list.
1139        *
1140        *  The elements of @a x are inserted in constant time in front of
1141        *  the element referenced by @a position.  @a x becomes an empty
1142        *  list.
1143        *
1144        *  Requires this != @a x.
1145        */
1146       void
1147 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1148       splice(iterator __position, list&& __x)
1149 #else
1150       splice(iterator __position, list& __x)
1151 #endif
1152       {
1153         if (!__x.empty())
1154           {
1155             _M_check_equal_allocators(__x);
1156
1157             this->_M_transfer(__position, __x.begin(), __x.end());
1158           }
1159       }
1160
1161 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1162       void
1163       splice(iterator __position, list& __x)
1164       { splice(__position, std::move(__x)); }
1165 #endif
1166
1167       /**
1168        *  @brief  Insert element from another %list.
1169        *  @param  position  Iterator referencing the element to insert before.
1170        *  @param  x  Source list.
1171        *  @param  i  Iterator referencing the element to move.
1172        *
1173        *  Removes the element in list @a x referenced by @a i and
1174        *  inserts it into the current list before @a position.
1175        */
1176       void
1177 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1178       splice(iterator __position, list&& __x, iterator __i)
1179 #else
1180       splice(iterator __position, list& __x, iterator __i)
1181 #endif
1182       {
1183         iterator __j = __i;
1184         ++__j;
1185         if (__position == __i || __position == __j)
1186           return;
1187
1188         if (this != &__x)
1189           _M_check_equal_allocators(__x);
1190
1191         this->_M_transfer(__position, __i, __j);
1192       }
1193
1194 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1195       void
1196       splice(iterator __position, list& __x, iterator __i)
1197       { splice(__position, std::move(__x), __i); }
1198 #endif
1199
1200       /**
1201        *  @brief  Insert range from another %list.
1202        *  @param  position  Iterator referencing the element to insert before.
1203        *  @param  x  Source list.
1204        *  @param  first  Iterator referencing the start of range in x.
1205        *  @param  last  Iterator referencing the end of range in x.
1206        *
1207        *  Removes elements in the range [first,last) and inserts them
1208        *  before @a position in constant time.
1209        *
1210        *  Undefined if @a position is in [first,last).
1211        */
1212       void
1213 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1214       splice(iterator __position, list&& __x, iterator __first,
1215              iterator __last)
1216 #else
1217       splice(iterator __position, list& __x, iterator __first,
1218              iterator __last)
1219 #endif
1220       {
1221         if (__first != __last)
1222           {
1223             if (this != &__x)
1224               _M_check_equal_allocators(__x);
1225
1226             this->_M_transfer(__position, __first, __last);
1227           }
1228       }
1229
1230 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1231       void
1232       splice(iterator __position, list& __x, iterator __first, iterator __last)
1233       { splice(__position, std::move(__x), __first, __last); }
1234 #endif
1235
1236       /**
1237        *  @brief  Remove all elements equal to value.
1238        *  @param  value  The value to remove.
1239        *
1240        *  Removes every element in the list equal to @a value.
1241        *  Remaining elements stay in list order.  Note that this
1242        *  function only erases the elements, and that if the elements
1243        *  themselves are pointers, the pointed-to memory is not
1244        *  touched in any way.  Managing the pointer is the user's
1245        *  responsibility.
1246        */
1247       void
1248       remove(const _Tp& __value);
1249
1250       /**
1251        *  @brief  Remove all elements satisfying a predicate.
1252        *  @param  Predicate  Unary predicate function or object.
1253        *
1254        *  Removes every element in the list for which the predicate
1255        *  returns true.  Remaining elements stay in list order.  Note
1256        *  that this function only erases the elements, and that if the
1257        *  elements themselves are pointers, the pointed-to memory is
1258        *  not touched in any way.  Managing the pointer is the user's
1259        *  responsibility.
1260        */
1261       template<typename _Predicate>
1262         void
1263         remove_if(_Predicate);
1264
1265       /**
1266        *  @brief  Remove consecutive duplicate elements.
1267        *
1268        *  For each consecutive set of elements with the same value,
1269        *  remove all but the first one.  Remaining elements stay in
1270        *  list order.  Note that this function only erases the
1271        *  elements, and that if the elements themselves are pointers,
1272        *  the pointed-to memory is not touched in any way.  Managing
1273        *  the pointer is the user's responsibility.
1274        */
1275       void
1276       unique();
1277
1278       /**
1279        *  @brief  Remove consecutive elements satisfying a predicate.
1280        *  @param  BinaryPredicate  Binary predicate function or object.
1281        *
1282        *  For each consecutive set of elements [first,last) that
1283        *  satisfy predicate(first,i) where i is an iterator in
1284        *  [first,last), remove all but the first one.  Remaining
1285        *  elements stay in list order.  Note that this function only
1286        *  erases the elements, and that if the elements themselves are
1287        *  pointers, the pointed-to memory is not touched in any way.
1288        *  Managing the pointer is the user's responsibility.
1289        */
1290       template<typename _BinaryPredicate>
1291         void
1292         unique(_BinaryPredicate);
1293
1294       /**
1295        *  @brief  Merge sorted lists.
1296        *  @param  x  Sorted list to merge.
1297        *
1298        *  Assumes that both @a x and this list are sorted according to
1299        *  operator<().  Merges elements of @a x into this list in
1300        *  sorted order, leaving @a x empty when complete.  Elements in
1301        *  this list precede elements in @a x that are equal.
1302        */
1303 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1304       void
1305       merge(list&& __x);
1306
1307       void
1308       merge(list& __x)
1309       { merge(std::move(__x)); }
1310 #else
1311       void
1312       merge(list& __x);
1313 #endif
1314
1315       /**
1316        *  @brief  Merge sorted lists according to comparison function.
1317        *  @param  x  Sorted list to merge.
1318        *  @param StrictWeakOrdering Comparison function defining
1319        *  sort order.
1320        *
1321        *  Assumes that both @a x and this list are sorted according to
1322        *  StrictWeakOrdering.  Merges elements of @a x into this list
1323        *  in sorted order, leaving @a x empty when complete.  Elements
1324        *  in this list precede elements in @a x that are equivalent
1325        *  according to StrictWeakOrdering().
1326        */
1327 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1328       template<typename _StrictWeakOrdering>
1329         void
1330         merge(list&&, _StrictWeakOrdering);
1331
1332       template<typename _StrictWeakOrdering>
1333         void
1334         merge(list& __x, _StrictWeakOrdering __comp)
1335         { merge(std::move(__x), __comp); }
1336 #else
1337       template<typename _StrictWeakOrdering>
1338         void
1339         merge(list&, _StrictWeakOrdering);
1340 #endif
1341
1342       /**
1343        *  @brief  Reverse the elements in list.
1344        *
1345        *  Reverse the order of elements in the list in linear time.
1346        */
1347       void
1348       reverse()
1349       { this->_M_impl._M_node._M_reverse(); }
1350
1351       /**
1352        *  @brief  Sort the elements.
1353        *
1354        *  Sorts the elements of this list in NlogN time.  Equivalent
1355        *  elements remain in list order.
1356        */
1357       void
1358       sort();
1359
1360       /**
1361        *  @brief  Sort the elements according to comparison function.
1362        *
1363        *  Sorts the elements of this list in NlogN time.  Equivalent
1364        *  elements remain in list order.
1365        */
1366       template<typename _StrictWeakOrdering>
1367         void
1368         sort(_StrictWeakOrdering);
1369
1370     protected:
1371       // Internal constructor functions follow.
1372
1373       // Called by the range constructor to implement [23.1.1]/9
1374
1375       // _GLIBCXX_RESOLVE_LIB_DEFECTS
1376       // 438. Ambiguity in the "do the right thing" clause
1377       template<typename _Integer>
1378         void
1379         _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1380         { _M_fill_initialize(static_cast<size_type>(__n), __x); }
1381
1382       // Called by the range constructor to implement [23.1.1]/9
1383       template<typename _InputIterator>
1384         void
1385         _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1386                                __false_type)
1387         {
1388           for (; __first != __last; ++__first)
1389             push_back(*__first);
1390         }
1391
1392       // Called by list(n,v,a), and the range constructor when it turns out
1393       // to be the same thing.
1394       void
1395       _M_fill_initialize(size_type __n, const value_type& __x)
1396       {
1397         for (; __n > 0; --__n)
1398           push_back(__x);
1399       }
1400
1401
1402       // Internal assign functions follow.
1403
1404       // Called by the range assign to implement [23.1.1]/9
1405
1406       // _GLIBCXX_RESOLVE_LIB_DEFECTS
1407       // 438. Ambiguity in the "do the right thing" clause
1408       template<typename _Integer>
1409         void
1410         _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1411         { _M_fill_assign(__n, __val); }
1412
1413       // Called by the range assign to implement [23.1.1]/9
1414       template<typename _InputIterator>
1415         void
1416         _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1417                            __false_type);
1418
1419       // Called by assign(n,t), and the range assign when it turns out
1420       // to be the same thing.
1421       void
1422       _M_fill_assign(size_type __n, const value_type& __val);
1423
1424
1425       // Moves the elements from [first,last) before position.
1426       void
1427       _M_transfer(iterator __position, iterator __first, iterator __last)
1428       { __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
1429
1430       // Inserts new element at position given and with value given.
1431 #ifndef __GXX_EXPERIMENTAL_CXX0X__
1432       void
1433       _M_insert(iterator __position, const value_type& __x)
1434       {
1435         _Node* __tmp = _M_create_node(__x);
1436         __tmp->_M_hook(__position._M_node);
1437       }
1438 #else
1439      template<typename... _Args>
1440        void
1441        _M_insert(iterator __position, _Args&&... __args)
1442        {
1443          _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
1444          __tmp->_M_hook(__position._M_node);
1445        }
1446 #endif
1447
1448       // Erases element at position given.
1449       void
1450       _M_erase(iterator __position)
1451       {
1452         __position._M_node->_M_unhook();
1453         _Node* __n = static_cast<_Node*>(__position._M_node);
1454 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1455         _M_get_Node_allocator().destroy(__n);
1456 #else
1457         _M_get_Tp_allocator().destroy(std::__addressof(__n->_M_data));
1458 #endif
1459         _M_put_node(__n);
1460       }
1461
1462       // To implement the splice (and merge) bits of N1599.
1463       void
1464       _M_check_equal_allocators(list& __x)
1465       {
1466         if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
1467             _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
1468           __throw_runtime_error(__N("list::_M_check_equal_allocators"));
1469       }
1470     };
1471
1472   /**
1473    *  @brief  List equality comparison.
1474    *  @param  x  A %list.
1475    *  @param  y  A %list of the same type as @a x.
1476    *  @return  True iff the size and elements of the lists are equal.
1477    *
1478    *  This is an equivalence relation.  It is linear in the size of
1479    *  the lists.  Lists are considered equivalent if their sizes are
1480    *  equal, and if corresponding elements compare equal.
1481   */
1482   template<typename _Tp, typename _Alloc>
1483     inline bool
1484     operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1485     {
1486       typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
1487       const_iterator __end1 = __x.end();
1488       const_iterator __end2 = __y.end();
1489
1490       const_iterator __i1 = __x.begin();
1491       const_iterator __i2 = __y.begin();
1492       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
1493         {
1494           ++__i1;
1495           ++__i2;
1496         }
1497       return __i1 == __end1 && __i2 == __end2;
1498     }
1499
1500   /**
1501    *  @brief  List ordering relation.
1502    *  @param  x  A %list.
1503    *  @param  y  A %list of the same type as @a x.
1504    *  @return  True iff @a x is lexicographically less than @a y.
1505    *
1506    *  This is a total ordering relation.  It is linear in the size of the
1507    *  lists.  The elements must be comparable with @c <.
1508    *
1509    *  See std::lexicographical_compare() for how the determination is made.
1510   */
1511   template<typename _Tp, typename _Alloc>
1512     inline bool
1513     operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1514     { return std::lexicographical_compare(__x.begin(), __x.end(),
1515                                           __y.begin(), __y.end()); }
1516
1517   /// Based on operator==
1518   template<typename _Tp, typename _Alloc>
1519     inline bool
1520     operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1521     { return !(__x == __y); }
1522
1523   /// Based on operator<
1524   template<typename _Tp, typename _Alloc>
1525     inline bool
1526     operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1527     { return __y < __x; }
1528
1529   /// Based on operator<
1530   template<typename _Tp, typename _Alloc>
1531     inline bool
1532     operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1533     { return !(__y < __x); }
1534
1535   /// Based on operator<
1536   template<typename _Tp, typename _Alloc>
1537     inline bool
1538     operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
1539     { return !(__x < __y); }
1540
1541   /// See std::list::swap().
1542   template<typename _Tp, typename _Alloc>
1543     inline void
1544     swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
1545     { __x.swap(__y); }
1546
1547 _GLIBCXX_END_NESTED_NAMESPACE
1548
1549 #endif /* _STL_LIST_H */