OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [bits/] [stl_list.h] - Blame information for rev 35

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.