libstdc++
forward_list.h
Go to the documentation of this file.
1 // <forward_list.h> -*- C++ -*-
2 
3 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /** @file bits/forward_list.h
26  * This is an internal header file, included by other library headers.
27  * Do not attempt to use it directly. @headername{forward_list}
28  */
29 
30 #ifndef _FORWARD_LIST_H
31 #define _FORWARD_LIST_H 1
32 
33 #pragma GCC system_header
34 
35 #include <initializer_list>
37 #include <bits/stl_iterator.h>
38 #include <bits/stl_algobase.h>
39 #include <bits/stl_function.h>
40 #include <bits/allocator.h>
41 #include <ext/alloc_traits.h>
42 #include <ext/aligned_buffer.h>
43 
44 namespace std _GLIBCXX_VISIBILITY(default)
45 {
46 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
47 
48  /**
49  * @brief A helper basic node class for %forward_list.
50  * This is just a linked list with nothing inside it.
51  * There are purely list shuffling utility methods here.
52  */
54  {
55  _Fwd_list_node_base() = default;
56 
57  _Fwd_list_node_base* _M_next = nullptr;
58 
60  _M_transfer_after(_Fwd_list_node_base* __begin,
61  _Fwd_list_node_base* __end) noexcept
62  {
63  _Fwd_list_node_base* __keep = __begin->_M_next;
64  if (__end)
65  {
66  __begin->_M_next = __end->_M_next;
67  __end->_M_next = _M_next;
68  }
69  else
70  __begin->_M_next = 0;
71  _M_next = __keep;
72  return __end;
73  }
74 
75  void
76  _M_reverse_after() noexcept
77  {
78  _Fwd_list_node_base* __tail = _M_next;
79  if (!__tail)
80  return;
81  while (_Fwd_list_node_base* __temp = __tail->_M_next)
82  {
83  _Fwd_list_node_base* __keep = _M_next;
84  _M_next = __temp;
85  __tail->_M_next = __temp->_M_next;
86  _M_next->_M_next = __keep;
87  }
88  }
89  };
90 
91  /**
92  * @brief A helper node class for %forward_list.
93  * This is just a linked list with uninitialized storage for a
94  * data value in each node.
95  * There is a sorting utility method.
96  */
97  template<typename _Tp>
99  : public _Fwd_list_node_base
100  {
101  _Fwd_list_node() = default;
102 
103  __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
104 
105  _Tp*
106  _M_valptr() noexcept
107  { return _M_storage._M_ptr(); }
108 
109  const _Tp*
110  _M_valptr() const noexcept
111  { return _M_storage._M_ptr(); }
112  };
113 
114  /**
115  * @brief A forward_list::iterator.
116  *
117  * All the functions are op overloads.
118  */
119  template<typename _Tp>
121  {
123  typedef _Fwd_list_node<_Tp> _Node;
124 
125  typedef _Tp value_type;
126  typedef _Tp* pointer;
127  typedef _Tp& reference;
128  typedef ptrdiff_t difference_type;
130 
131  _Fwd_list_iterator() noexcept
132  : _M_node() { }
133 
134  explicit
136  : _M_node(__n) { }
137 
138  reference
139  operator*() const noexcept
140  { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
141 
142  pointer
143  operator->() const noexcept
144  { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
145 
146  _Self&
147  operator++() noexcept
148  {
149  _M_node = _M_node->_M_next;
150  return *this;
151  }
152 
153  _Self
154  operator++(int) noexcept
155  {
156  _Self __tmp(*this);
157  _M_node = _M_node->_M_next;
158  return __tmp;
159  }
160 
161  bool
162  operator==(const _Self& __x) const noexcept
163  { return _M_node == __x._M_node; }
164 
165  bool
166  operator!=(const _Self& __x) const noexcept
167  { return _M_node != __x._M_node; }
168 
169  _Self
170  _M_next() const noexcept
171  {
172  if (_M_node)
173  return _Fwd_list_iterator(_M_node->_M_next);
174  else
175  return _Fwd_list_iterator(0);
176  }
177 
178  _Fwd_list_node_base* _M_node;
179  };
180 
181  /**
182  * @brief A forward_list::const_iterator.
183  *
184  * All the functions are op overloads.
185  */
186  template<typename _Tp>
188  {
190  typedef const _Fwd_list_node<_Tp> _Node;
192 
193  typedef _Tp value_type;
194  typedef const _Tp* pointer;
195  typedef const _Tp& reference;
196  typedef ptrdiff_t difference_type;
198 
199  _Fwd_list_const_iterator() noexcept
200  : _M_node() { }
201 
202  explicit
203  _Fwd_list_const_iterator(const _Fwd_list_node_base* __n) noexcept
204  : _M_node(__n) { }
205 
206  _Fwd_list_const_iterator(const iterator& __iter) noexcept
207  : _M_node(__iter._M_node) { }
208 
209  reference
210  operator*() const noexcept
211  { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
212 
213  pointer
214  operator->() const noexcept
215  { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
216 
217  _Self&
218  operator++() noexcept
219  {
220  _M_node = _M_node->_M_next;
221  return *this;
222  }
223 
224  _Self
225  operator++(int) noexcept
226  {
227  _Self __tmp(*this);
228  _M_node = _M_node->_M_next;
229  return __tmp;
230  }
231 
232  bool
233  operator==(const _Self& __x) const noexcept
234  { return _M_node == __x._M_node; }
235 
236  bool
237  operator!=(const _Self& __x) const noexcept
238  { return _M_node != __x._M_node; }
239 
240  _Self
241  _M_next() const noexcept
242  {
243  if (this->_M_node)
244  return _Fwd_list_const_iterator(_M_node->_M_next);
245  else
246  return _Fwd_list_const_iterator(0);
247  }
248 
249  const _Fwd_list_node_base* _M_node;
250  };
251 
252  /**
253  * @brief Forward list iterator equality comparison.
254  */
255  template<typename _Tp>
256  inline bool
257  operator==(const _Fwd_list_iterator<_Tp>& __x,
258  const _Fwd_list_const_iterator<_Tp>& __y) noexcept
259  { return __x._M_node == __y._M_node; }
260 
261  /**
262  * @brief Forward list iterator inequality comparison.
263  */
264  template<typename _Tp>
265  inline bool
266  operator!=(const _Fwd_list_iterator<_Tp>& __x,
267  const _Fwd_list_const_iterator<_Tp>& __y) noexcept
268  { return __x._M_node != __y._M_node; }
269 
270  /**
271  * @brief Base class for %forward_list.
272  */
273  template<typename _Tp, typename _Alloc>
275  {
276  protected:
277  typedef __alloc_rebind<_Alloc, _Tp> _Tp_alloc_type;
278  typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
280 
281  struct _Fwd_list_impl
282  : public _Node_alloc_type
283  {
284  _Fwd_list_node_base _M_head;
285 
286  _Fwd_list_impl()
287  : _Node_alloc_type(), _M_head()
288  { }
289 
290  _Fwd_list_impl(const _Node_alloc_type& __a)
291  : _Node_alloc_type(__a), _M_head()
292  { }
293 
294  _Fwd_list_impl(_Node_alloc_type&& __a)
295  : _Node_alloc_type(std::move(__a)), _M_head()
296  { }
297  };
298 
299  _Fwd_list_impl _M_impl;
300 
301  public:
304  typedef _Fwd_list_node<_Tp> _Node;
305 
306  _Node_alloc_type&
307  _M_get_Node_allocator() noexcept
308  { return *static_cast<_Node_alloc_type*>(&this->_M_impl); }
309 
310  const _Node_alloc_type&
311  _M_get_Node_allocator() const noexcept
312  { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
313 
315  : _M_impl() { }
316 
317  _Fwd_list_base(const _Node_alloc_type& __a)
318  : _M_impl(__a) { }
319 
320  _Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a);
321 
323  : _M_impl(std::move(__lst._M_get_Node_allocator()))
324  {
325  this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
326  __lst._M_impl._M_head._M_next = 0;
327  }
328 
329  ~_Fwd_list_base()
330  { _M_erase_after(&_M_impl._M_head, 0); }
331 
332  protected:
333 
334  _Node*
335  _M_get_node()
336  {
337  auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
338  return std::__addressof(*__ptr);
339  }
340 
341  template<typename... _Args>
342  _Node*
343  _M_create_node(_Args&&... __args)
344  {
345  _Node* __node = this->_M_get_node();
346  __try
347  {
348  _Tp_alloc_type __a(_M_get_Node_allocator());
349  typedef allocator_traits<_Tp_alloc_type> _Alloc_traits;
350  ::new ((void*)__node) _Node;
351  _Alloc_traits::construct(__a, __node->_M_valptr(),
352  std::forward<_Args>(__args)...);
353  }
354  __catch(...)
355  {
356  this->_M_put_node(__node);
357  __throw_exception_again;
358  }
359  return __node;
360  }
361 
362  template<typename... _Args>
364  _M_insert_after(const_iterator __pos, _Args&&... __args);
365 
366  void
367  _M_put_node(_Node* __p)
368  {
369  typedef typename _Node_alloc_traits::pointer _Ptr;
370  auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__p);
371  _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
372  }
373 
375  _M_erase_after(_Fwd_list_node_base* __pos);
376 
378  _M_erase_after(_Fwd_list_node_base* __pos,
379  _Fwd_list_node_base* __last);
380  };
381 
382  /**
383  * @brief A standard container with linear time access to elements,
384  * and fixed time insertion/deletion at any point in the sequence.
385  *
386  * @ingroup sequences
387  *
388  * @tparam _Tp Type of element.
389  * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
390  *
391  * Meets the requirements of a <a href="tables.html#65">container</a>, a
392  * <a href="tables.html#67">sequence</a>, including the
393  * <a href="tables.html#68">optional sequence requirements</a> with the
394  * %exception of @c at and @c operator[].
395  *
396  * This is a @e singly @e linked %list. Traversal up the
397  * %list requires linear time, but adding and removing elements (or
398  * @e nodes) is done in constant time, regardless of where the
399  * change takes place. Unlike std::vector and std::deque,
400  * random-access iterators are not provided, so subscripting ( @c
401  * [] ) access is not allowed. For algorithms which only need
402  * sequential access, this lack makes no difference.
403  *
404  * Also unlike the other standard containers, std::forward_list provides
405  * specialized algorithms %unique to linked lists, such as
406  * splicing, sorting, and in-place reversal.
407  */
408  template<typename _Tp, typename _Alloc = allocator<_Tp> >
409  class forward_list : private _Fwd_list_base<_Tp, _Alloc>
410  {
411  private:
413  typedef _Fwd_list_node<_Tp> _Node;
415  typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
416  typedef typename _Base::_Node_alloc_type _Node_alloc_type;
419 
420  public:
421  // types:
422  typedef _Tp value_type;
423  typedef typename _Alloc_traits::pointer pointer;
424  typedef typename _Alloc_traits::const_pointer const_pointer;
425  typedef value_type& reference;
426  typedef const value_type& const_reference;
427 
430  typedef std::size_t size_type;
431  typedef std::ptrdiff_t difference_type;
432  typedef _Alloc allocator_type;
433 
434  // 23.3.4.2 construct/copy/destroy:
435 
436  /**
437  * @brief Creates a %forward_list with no elements.
438  * @param __al An allocator object.
439  */
440  explicit
441  forward_list(const _Alloc& __al = _Alloc())
442  : _Base(_Node_alloc_type(__al))
443  { }
444 
445  /**
446  * @brief Copy constructor with allocator argument.
447  * @param __list Input list to copy.
448  * @param __al An allocator object.
449  */
450  forward_list(const forward_list& __list, const _Alloc& __al)
451  : _Base(_Node_alloc_type(__al))
452  { _M_range_initialize(__list.begin(), __list.end()); }
453 
454  /**
455  * @brief Move constructor with allocator argument.
456  * @param __list Input list to move.
457  * @param __al An allocator object.
458  */
459  forward_list(forward_list&& __list, const _Alloc& __al)
460  noexcept(_Node_alloc_traits::_S_always_equal())
461  : _Base(std::move(__list), _Node_alloc_type(__al))
462  { }
463 
464  /**
465  * @brief Creates a %forward_list with default constructed elements.
466  * @param __n The number of elements to initially create.
467  *
468  * This constructor creates the %forward_list with @a __n default
469  * constructed elements.
470  */
471  explicit
472  forward_list(size_type __n, const _Alloc& __al = _Alloc())
473  : _Base(_Node_alloc_type(__al))
474  { _M_default_initialize(__n); }
475 
476  /**
477  * @brief Creates a %forward_list with copies of an exemplar element.
478  * @param __n The number of elements to initially create.
479  * @param __value An element to copy.
480  * @param __al An allocator object.
481  *
482  * This constructor fills the %forward_list with @a __n copies of
483  * @a __value.
484  */
485  forward_list(size_type __n, const _Tp& __value,
486  const _Alloc& __al = _Alloc())
487  : _Base(_Node_alloc_type(__al))
488  { _M_fill_initialize(__n, __value); }
489 
490  /**
491  * @brief Builds a %forward_list from a range.
492  * @param __first An input iterator.
493  * @param __last An input iterator.
494  * @param __al An allocator object.
495  *
496  * Create a %forward_list consisting of copies of the elements from
497  * [@a __first,@a __last). This is linear in N (where N is
498  * distance(@a __first,@a __last)).
499  */
500  template<typename _InputIterator,
501  typename = std::_RequireInputIter<_InputIterator>>
502  forward_list(_InputIterator __first, _InputIterator __last,
503  const _Alloc& __al = _Alloc())
504  : _Base(_Node_alloc_type(__al))
505  { _M_range_initialize(__first, __last); }
506 
507  /**
508  * @brief The %forward_list copy constructor.
509  * @param __list A %forward_list of identical element and allocator
510  * types.
511  */
512  forward_list(const forward_list& __list)
513  : _Base(_Node_alloc_traits::_S_select_on_copy(
514  __list._M_get_Node_allocator()))
515  { _M_range_initialize(__list.begin(), __list.end()); }
516 
517  /**
518  * @brief The %forward_list move constructor.
519  * @param __list A %forward_list of identical element and allocator
520  * types.
521  *
522  * The newly-created %forward_list contains the exact contents of @a
523  * __list. The contents of @a __list are a valid, but unspecified
524  * %forward_list.
525  */
526  forward_list(forward_list&& __list) noexcept
527  : _Base(std::move(__list)) { }
528 
529  /**
530  * @brief Builds a %forward_list from an initializer_list
531  * @param __il An initializer_list of value_type.
532  * @param __al An allocator object.
533  *
534  * Create a %forward_list consisting of copies of the elements
535  * in the initializer_list @a __il. This is linear in __il.size().
536  */
537  forward_list(std::initializer_list<_Tp> __il,
538  const _Alloc& __al = _Alloc())
539  : _Base(_Node_alloc_type(__al))
540  { _M_range_initialize(__il.begin(), __il.end()); }
541 
542  /**
543  * @brief The forward_list dtor.
544  */
545  ~forward_list() noexcept
546  { }
547 
548  /**
549  * @brief The %forward_list assignment operator.
550  * @param __list A %forward_list of identical element and allocator
551  * types.
552  *
553  * All the elements of @a __list are copied, but unlike the copy
554  * constructor, the allocator object is not copied.
555  */
556  forward_list&
557  operator=(const forward_list& __list);
558 
559  /**
560  * @brief The %forward_list move assignment operator.
561  * @param __list A %forward_list of identical element and allocator
562  * types.
563  *
564  * The contents of @a __list are moved into this %forward_list
565  * (without copying, if the allocators permit it).
566  * @a __list is a valid, but unspecified %forward_list
567  */
568  forward_list&
570  noexcept(_Node_alloc_traits::_S_nothrow_move())
571  {
572  constexpr bool __move_storage =
573  _Node_alloc_traits::_S_propagate_on_move_assign()
574  || _Node_alloc_traits::_S_always_equal();
575  _M_move_assign(std::move(__list),
576  integral_constant<bool, __move_storage>());
577  return *this;
578  }
579 
580  /**
581  * @brief The %forward_list initializer list assignment operator.
582  * @param __il An initializer_list of value_type.
583  *
584  * Replace the contents of the %forward_list with copies of the
585  * elements in the initializer_list @a __il. This is linear in
586  * __il.size().
587  */
588  forward_list&
589  operator=(std::initializer_list<_Tp> __il)
590  {
591  assign(__il);
592  return *this;
593  }
594 
595  /**
596  * @brief Assigns a range to a %forward_list.
597  * @param __first An input iterator.
598  * @param __last An input iterator.
599  *
600  * This function fills a %forward_list with copies of the elements
601  * in the range [@a __first,@a __last).
602  *
603  * Note that the assignment completely changes the %forward_list and
604  * that the number of elements of the resulting %forward_list is the
605  * same as the number of elements assigned. Old data is lost.
606  */
607  template<typename _InputIterator,
608  typename = std::_RequireInputIter<_InputIterator>>
609  void
610  assign(_InputIterator __first, _InputIterator __last)
611  {
612  typedef is_assignable<_Tp, decltype(*__first)> __assignable;
613  _M_assign(__first, __last, __assignable());
614  }
615 
616  /**
617  * @brief Assigns a given value to a %forward_list.
618  * @param __n Number of elements to be assigned.
619  * @param __val Value to be assigned.
620  *
621  * This function fills a %forward_list with @a __n copies of the
622  * given value. Note that the assignment completely changes the
623  * %forward_list, and that the resulting %forward_list has __n
624  * elements. Old data is lost.
625  */
626  void
627  assign(size_type __n, const _Tp& __val)
628  { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
629 
630  /**
631  * @brief Assigns an initializer_list to a %forward_list.
632  * @param __il An initializer_list of value_type.
633  *
634  * Replace the contents of the %forward_list with copies of the
635  * elements in the initializer_list @a __il. This is linear in
636  * il.size().
637  */
638  void
639  assign(std::initializer_list<_Tp> __il)
640  { assign(__il.begin(), __il.end()); }
641 
642  /// Get a copy of the memory allocation object.
643  allocator_type
644  get_allocator() const noexcept
645  { return allocator_type(this->_M_get_Node_allocator()); }
646 
647  // 23.3.4.3 iterators:
648 
649  /**
650  * Returns a read/write iterator that points before the first element
651  * in the %forward_list. Iteration is done in ordinary element order.
652  */
653  iterator
654  before_begin() noexcept
655  { return iterator(&this->_M_impl._M_head); }
656 
657  /**
658  * Returns a read-only (constant) iterator that points before the
659  * first element in the %forward_list. Iteration is done in ordinary
660  * element order.
661  */
662  const_iterator
663  before_begin() const noexcept
664  { return const_iterator(&this->_M_impl._M_head); }
665 
666  /**
667  * Returns a read/write iterator that points to the first element
668  * in the %forward_list. Iteration is done in ordinary element order.
669  */
670  iterator
671  begin() noexcept
672  { return iterator(this->_M_impl._M_head._M_next); }
673 
674  /**
675  * Returns a read-only (constant) iterator that points to the first
676  * element in the %forward_list. Iteration is done in ordinary
677  * element order.
678  */
679  const_iterator
680  begin() const noexcept
681  { return const_iterator(this->_M_impl._M_head._M_next); }
682 
683  /**
684  * Returns a read/write iterator that points one past the last
685  * element in the %forward_list. Iteration is done in ordinary
686  * element order.
687  */
688  iterator
689  end() noexcept
690  { return iterator(0); }
691 
692  /**
693  * Returns a read-only iterator that points one past the last
694  * element in the %forward_list. Iteration is done in ordinary
695  * element order.
696  */
697  const_iterator
698  end() const noexcept
699  { return const_iterator(0); }
700 
701  /**
702  * Returns a read-only (constant) iterator that points to the
703  * first element in the %forward_list. Iteration is done in ordinary
704  * element order.
705  */
706  const_iterator
707  cbegin() const noexcept
708  { return const_iterator(this->_M_impl._M_head._M_next); }
709 
710  /**
711  * Returns a read-only (constant) iterator that points before the
712  * first element in the %forward_list. Iteration is done in ordinary
713  * element order.
714  */
715  const_iterator
716  cbefore_begin() const noexcept
717  { return const_iterator(&this->_M_impl._M_head); }
718 
719  /**
720  * Returns a read-only (constant) iterator that points one past
721  * the last element in the %forward_list. Iteration is done in
722  * ordinary element order.
723  */
724  const_iterator
725  cend() const noexcept
726  { return const_iterator(0); }
727 
728  /**
729  * Returns true if the %forward_list is empty. (Thus begin() would
730  * equal end().)
731  */
732  bool
733  empty() const noexcept
734  { return this->_M_impl._M_head._M_next == 0; }
735 
736  /**
737  * Returns the largest possible number of elements of %forward_list.
738  */
739  size_type
740  max_size() const noexcept
741  { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
742 
743  // 23.3.4.4 element access:
744 
745  /**
746  * Returns a read/write reference to the data at the first
747  * element of the %forward_list.
748  */
749  reference
751  {
752  _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
753  return *__front->_M_valptr();
754  }
755 
756  /**
757  * Returns a read-only (constant) reference to the data at the first
758  * element of the %forward_list.
759  */
760  const_reference
761  front() const
762  {
763  _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
764  return *__front->_M_valptr();
765  }
766 
767  // 23.3.4.5 modifiers:
768 
769  /**
770  * @brief Constructs object in %forward_list at the front of the
771  * list.
772  * @param __args Arguments.
773  *
774  * This function will insert an object of type Tp constructed
775  * with Tp(std::forward<Args>(args)...) at the front of the list
776  * Due to the nature of a %forward_list this operation can
777  * be done in constant time, and does not invalidate iterators
778  * and references.
779  */
780  template<typename... _Args>
781  void
782  emplace_front(_Args&&... __args)
783  { this->_M_insert_after(cbefore_begin(),
784  std::forward<_Args>(__args)...); }
785 
786  /**
787  * @brief Add data to the front of the %forward_list.
788  * @param __val Data to be added.
789  *
790  * This is a typical stack operation. The function creates an
791  * element at the front of the %forward_list and assigns the given
792  * data to it. Due to the nature of a %forward_list this operation
793  * can be done in constant time, and does not invalidate iterators
794  * and references.
795  */
796  void
797  push_front(const _Tp& __val)
798  { this->_M_insert_after(cbefore_begin(), __val); }
799 
800  /**
801  *
802  */
803  void
804  push_front(_Tp&& __val)
805  { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
806 
807  /**
808  * @brief Removes first element.
809  *
810  * This is a typical stack operation. It shrinks the %forward_list
811  * by one. Due to the nature of a %forward_list this operation can
812  * be done in constant time, and only invalidates iterators/references
813  * to the element being removed.
814  *
815  * Note that no data is returned, and if the first element's data
816  * is needed, it should be retrieved before pop_front() is
817  * called.
818  */
819  void
821  { this->_M_erase_after(&this->_M_impl._M_head); }
822 
823  /**
824  * @brief Constructs object in %forward_list after the specified
825  * iterator.
826  * @param __pos A const_iterator into the %forward_list.
827  * @param __args Arguments.
828  * @return An iterator that points to the inserted data.
829  *
830  * This function will insert an object of type T constructed
831  * with T(std::forward<Args>(args)...) after the specified
832  * location. Due to the nature of a %forward_list this operation can
833  * be done in constant time, and does not invalidate iterators
834  * and references.
835  */
836  template<typename... _Args>
837  iterator
838  emplace_after(const_iterator __pos, _Args&&... __args)
839  { return iterator(this->_M_insert_after(__pos,
840  std::forward<_Args>(__args)...)); }
841 
842  /**
843  * @brief Inserts given value into %forward_list after specified
844  * iterator.
845  * @param __pos An iterator into the %forward_list.
846  * @param __val Data to be inserted.
847  * @return An iterator that points to the inserted data.
848  *
849  * This function will insert a copy of the given value after
850  * the specified location. Due to the nature of a %forward_list this
851  * operation can be done in constant time, and does not
852  * invalidate iterators and references.
853  */
854  iterator
855  insert_after(const_iterator __pos, const _Tp& __val)
856  { return iterator(this->_M_insert_after(__pos, __val)); }
857 
858  /**
859  *
860  */
861  iterator
862  insert_after(const_iterator __pos, _Tp&& __val)
863  { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
864 
865  /**
866  * @brief Inserts a number of copies of given data into the
867  * %forward_list.
868  * @param __pos An iterator into the %forward_list.
869  * @param __n Number of elements to be inserted.
870  * @param __val Data to be inserted.
871  * @return An iterator pointing to the last inserted copy of
872  * @a val or @a pos if @a n == 0.
873  *
874  * This function will insert a specified number of copies of the
875  * given data after the location specified by @a pos.
876  *
877  * This operation is linear in the number of elements inserted and
878  * does not invalidate iterators and references.
879  */
880  iterator
881  insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
882 
883  /**
884  * @brief Inserts a range into the %forward_list.
885  * @param __pos An iterator into the %forward_list.
886  * @param __first An input iterator.
887  * @param __last An input iterator.
888  * @return An iterator pointing to the last inserted element or
889  * @a __pos if @a __first == @a __last.
890  *
891  * This function will insert copies of the data in the range
892  * [@a __first,@a __last) into the %forward_list after the
893  * location specified by @a __pos.
894  *
895  * This operation is linear in the number of elements inserted and
896  * does not invalidate iterators and references.
897  */
898  template<typename _InputIterator,
899  typename = std::_RequireInputIter<_InputIterator>>
900  iterator
901  insert_after(const_iterator __pos,
902  _InputIterator __first, _InputIterator __last);
903 
904  /**
905  * @brief Inserts the contents of an initializer_list into
906  * %forward_list after the specified iterator.
907  * @param __pos An iterator into the %forward_list.
908  * @param __il An initializer_list of value_type.
909  * @return An iterator pointing to the last inserted element
910  * or @a __pos if @a __il is empty.
911  *
912  * This function will insert copies of the data in the
913  * initializer_list @a __il into the %forward_list before the location
914  * specified by @a __pos.
915  *
916  * This operation is linear in the number of elements inserted and
917  * does not invalidate iterators and references.
918  */
919  iterator
920  insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
921  { return insert_after(__pos, __il.begin(), __il.end()); }
922 
923  /**
924  * @brief Removes the element pointed to by the iterator following
925  * @c pos.
926  * @param __pos Iterator pointing before element to be erased.
927  * @return An iterator pointing to the element following the one
928  * that was erased, or end() if no such element exists.
929  *
930  * This function will erase the element at the given position and
931  * thus shorten the %forward_list by one.
932  *
933  * Due to the nature of a %forward_list this operation can be done
934  * in constant time, and only invalidates iterators/references to
935  * the element being removed. The user is also cautioned that
936  * this function only erases the element, and that if the element
937  * is itself a pointer, the pointed-to memory is not touched in
938  * any way. Managing the pointer is the user's responsibility.
939  */
940  iterator
941  erase_after(const_iterator __pos)
942  { return iterator(this->_M_erase_after(const_cast<_Node_base*>
943  (__pos._M_node))); }
944 
945  /**
946  * @brief Remove a range of elements.
947  * @param __pos Iterator pointing before the first element to be
948  * erased.
949  * @param __last Iterator pointing to one past the last element to be
950  * erased.
951  * @return @ __last.
952  *
953  * This function will erase the elements in the range
954  * @a (__pos,__last) and shorten the %forward_list accordingly.
955  *
956  * This operation is linear time in the size of the range and only
957  * invalidates iterators/references to the element being removed.
958  * The user is also cautioned that this function only erases the
959  * elements, and that if the elements themselves are pointers, the
960  * pointed-to memory is not touched in any way. Managing the pointer
961  * is the user's responsibility.
962  */
963  iterator
964  erase_after(const_iterator __pos, const_iterator __last)
965  { return iterator(this->_M_erase_after(const_cast<_Node_base*>
966  (__pos._M_node),
967  const_cast<_Node_base*>
968  (__last._M_node))); }
969 
970  /**
971  * @brief Swaps data with another %forward_list.
972  * @param __list A %forward_list of the same element and allocator
973  * types.
974  *
975  * This exchanges the elements between two lists in constant
976  * time. Note that the global std::swap() function is
977  * specialized such that std::swap(l1,l2) will feed to this
978  * function.
979  */
980  void
982  noexcept(_Node_alloc_traits::_S_nothrow_swap())
983  {
984  std::swap(this->_M_impl._M_head._M_next,
985  __list._M_impl._M_head._M_next);
986  _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
987  __list._M_get_Node_allocator());
988  }
989 
990  /**
991  * @brief Resizes the %forward_list to the specified number of
992  * elements.
993  * @param __sz Number of elements the %forward_list should contain.
994  *
995  * This function will %resize the %forward_list to the specified
996  * number of elements. If the number is smaller than the
997  * %forward_list's current number of elements the %forward_list
998  * is truncated, otherwise the %forward_list is extended and the
999  * new elements are default constructed.
1000  */
1001  void
1002  resize(size_type __sz);
1003 
1004  /**
1005  * @brief Resizes the %forward_list to the specified number of
1006  * elements.
1007  * @param __sz Number of elements the %forward_list should contain.
1008  * @param __val Data with which new elements should be populated.
1009  *
1010  * This function will %resize the %forward_list to the specified
1011  * number of elements. If the number is smaller than the
1012  * %forward_list's current number of elements the %forward_list
1013  * is truncated, otherwise the %forward_list is extended and new
1014  * elements are populated with given data.
1015  */
1016  void
1017  resize(size_type __sz, const value_type& __val);
1018 
1019  /**
1020  * @brief Erases all the elements.
1021  *
1022  * Note that this function only erases
1023  * the elements, and that if the elements themselves are
1024  * pointers, the pointed-to memory is not touched in any way.
1025  * Managing the pointer is the user's responsibility.
1026  */
1027  void
1028  clear() noexcept
1029  { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1030 
1031  // 23.3.4.6 forward_list operations:
1032 
1033  /**
1034  * @brief Insert contents of another %forward_list.
1035  * @param __pos Iterator referencing the element to insert after.
1036  * @param __list Source list.
1037  *
1038  * The elements of @a list are inserted in constant time after
1039  * the element referenced by @a pos. @a list becomes an empty
1040  * list.
1041  *
1042  * Requires this != @a x.
1043  */
1044  void
1045  splice_after(const_iterator __pos, forward_list&& __list)
1046  {
1047  if (!__list.empty())
1048  _M_splice_after(__pos, __list.before_begin(), __list.end());
1049  }
1050 
1051  void
1052  splice_after(const_iterator __pos, forward_list& __list)
1053  { splice_after(__pos, std::move(__list)); }
1054 
1055  /**
1056  * @brief Insert element from another %forward_list.
1057  * @param __pos Iterator referencing the element to insert after.
1058  * @param __list Source list.
1059  * @param __i Iterator referencing the element before the element
1060  * to move.
1061  *
1062  * Removes the element in list @a list referenced by @a i and
1063  * inserts it into the current list after @a pos.
1064  */
1065  void
1066  splice_after(const_iterator __pos, forward_list&& __list,
1067  const_iterator __i);
1068 
1069  void
1070  splice_after(const_iterator __pos, forward_list& __list,
1071  const_iterator __i)
1072  { splice_after(__pos, std::move(__list), __i); }
1073 
1074  /**
1075  * @brief Insert range from another %forward_list.
1076  * @param __pos Iterator referencing the element to insert after.
1077  * @param __list Source list.
1078  * @param __before Iterator referencing before the start of range
1079  * in list.
1080  * @param __last Iterator referencing the end of range in list.
1081  *
1082  * Removes elements in the range (__before,__last) and inserts them
1083  * after @a __pos in constant time.
1084  *
1085  * Undefined if @a __pos is in (__before,__last).
1086  */
1087  void
1088  splice_after(const_iterator __pos, forward_list&&,
1089  const_iterator __before, const_iterator __last)
1090  { _M_splice_after(__pos, __before, __last); }
1091 
1092  void
1093  splice_after(const_iterator __pos, forward_list&,
1094  const_iterator __before, const_iterator __last)
1095  { _M_splice_after(__pos, __before, __last); }
1096 
1097  /**
1098  * @brief Remove all elements equal to value.
1099  * @param __val The value to remove.
1100  *
1101  * Removes every element in the list equal to @a __val.
1102  * Remaining elements stay in list order. Note that this
1103  * function only erases the elements, and that if the elements
1104  * themselves are pointers, the pointed-to memory is not
1105  * touched in any way. Managing the pointer is the user's
1106  * responsibility.
1107  */
1108  void
1109  remove(const _Tp& __val);
1110 
1111  /**
1112  * @brief Remove all elements satisfying a predicate.
1113  * @param __pred Unary predicate function or object.
1114  *
1115  * Removes every element in the list for which the predicate
1116  * returns true. Remaining elements stay in list order. Note
1117  * that this function only erases the elements, and that if the
1118  * elements themselves are pointers, the pointed-to memory is
1119  * not touched in any way. Managing the pointer is the user's
1120  * responsibility.
1121  */
1122  template<typename _Pred>
1123  void
1124  remove_if(_Pred __pred);
1125 
1126  /**
1127  * @brief Remove consecutive duplicate elements.
1128  *
1129  * For each consecutive set of elements with the same value,
1130  * remove all but the first one. Remaining elements stay in
1131  * list order. Note that this function only erases the
1132  * elements, and that if the elements themselves are pointers,
1133  * the pointed-to memory is not touched in any way. Managing
1134  * the pointer is the user's responsibility.
1135  */
1136  void
1138  { unique(std::equal_to<_Tp>()); }
1139 
1140  /**
1141  * @brief Remove consecutive elements satisfying a predicate.
1142  * @param __binary_pred Binary predicate function or object.
1143  *
1144  * For each consecutive set of elements [first,last) that
1145  * satisfy predicate(first,i) where i is an iterator in
1146  * [first,last), remove all but the first one. Remaining
1147  * elements stay in list order. Note that this function only
1148  * erases the elements, and that if the elements themselves are
1149  * pointers, the pointed-to memory is not touched in any way.
1150  * Managing the pointer is the user's responsibility.
1151  */
1152  template<typename _BinPred>
1153  void
1154  unique(_BinPred __binary_pred);
1155 
1156  /**
1157  * @brief Merge sorted lists.
1158  * @param __list Sorted list to merge.
1159  *
1160  * Assumes that both @a list and this list are sorted according to
1161  * operator<(). Merges elements of @a __list into this list in
1162  * sorted order, leaving @a __list empty when complete. Elements in
1163  * this list precede elements in @a __list that are equal.
1164  */
1165  void
1167  { merge(std::move(__list), std::less<_Tp>()); }
1168 
1169  void
1170  merge(forward_list& __list)
1171  { merge(std::move(__list)); }
1172 
1173  /**
1174  * @brief Merge sorted lists according to comparison function.
1175  * @param __list Sorted list to merge.
1176  * @param __comp Comparison function defining sort order.
1177  *
1178  * Assumes that both @a __list and this list are sorted according to
1179  * comp. Merges elements of @a __list into this list
1180  * in sorted order, leaving @a __list empty when complete. Elements
1181  * in this list precede elements in @a __list that are equivalent
1182  * according to comp().
1183  */
1184  template<typename _Comp>
1185  void
1186  merge(forward_list&& __list, _Comp __comp);
1187 
1188  template<typename _Comp>
1189  void
1190  merge(forward_list& __list, _Comp __comp)
1191  { merge(std::move(__list), __comp); }
1192 
1193  /**
1194  * @brief Sort the elements of the list.
1195  *
1196  * Sorts the elements of this list in NlogN time. Equivalent
1197  * elements remain in list order.
1198  */
1199  void
1201  { sort(std::less<_Tp>()); }
1202 
1203  /**
1204  * @brief Sort the forward_list using a comparison function.
1205  *
1206  * Sorts the elements of this list in NlogN time. Equivalent
1207  * elements remain in list order.
1208  */
1209  template<typename _Comp>
1210  void
1211  sort(_Comp __comp);
1212 
1213  /**
1214  * @brief Reverse the elements in list.
1215  *
1216  * Reverse the order of elements in the list in linear time.
1217  */
1218  void
1219  reverse() noexcept
1220  { this->_M_impl._M_head._M_reverse_after(); }
1221 
1222  private:
1223  // Called by the range constructor to implement [23.3.4.2]/9
1224  template<typename _InputIterator>
1225  void
1226  _M_range_initialize(_InputIterator __first, _InputIterator __last);
1227 
1228  // Called by forward_list(n,v,a), and the range constructor when it
1229  // turns out to be the same thing.
1230  void
1231  _M_fill_initialize(size_type __n, const value_type& __value);
1232 
1233  // Called by splice_after and insert_after.
1234  iterator
1235  _M_splice_after(const_iterator __pos, const_iterator __before,
1236  const_iterator __last);
1237 
1238  // Called by forward_list(n).
1239  void
1240  _M_default_initialize(size_type __n);
1241 
1242  // Called by resize(sz).
1243  void
1244  _M_default_insert_after(const_iterator __pos, size_type __n);
1245 
1246  // Called by operator=(forward_list&&)
1247  void
1248  _M_move_assign(forward_list&& __list, std::true_type) noexcept
1249  {
1250  clear();
1251  std::swap(this->_M_impl._M_head._M_next,
1252  __list._M_impl._M_head._M_next);
1253  std::__alloc_on_move(this->_M_get_Node_allocator(),
1254  __list._M_get_Node_allocator());
1255  }
1256 
1257  // Called by operator=(forward_list&&)
1258  void
1259  _M_move_assign(forward_list&& __list, std::false_type)
1260  {
1261  if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1262  _M_move_assign(std::move(__list), std::true_type());
1263  else
1264  // The rvalue's allocator cannot be moved, or is not equal,
1265  // so we need to individually move each element.
1266  this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1267  std::__make_move_if_noexcept_iterator(__list.end()));
1268  }
1269 
1270  // Called by assign(_InputIterator, _InputIterator) if _Tp is
1271  // CopyAssignable.
1272  template<typename _InputIterator>
1273  void
1274  _M_assign(_InputIterator __first, _InputIterator __last, true_type)
1275  {
1276  auto __prev = before_begin();
1277  auto __curr = begin();
1278  auto __end = end();
1279  while (__curr != __end && __first != __last)
1280  {
1281  *__curr = *__first;
1282  ++__prev;
1283  ++__curr;
1284  ++__first;
1285  }
1286  if (__first != __last)
1287  insert_after(__prev, __first, __last);
1288  else if (__curr != __end)
1289  erase_after(__prev, __end);
1290  }
1291 
1292  // Called by assign(_InputIterator, _InputIterator) if _Tp is not
1293  // CopyAssignable.
1294  template<typename _InputIterator>
1295  void
1296  _M_assign(_InputIterator __first, _InputIterator __last, false_type)
1297  {
1298  clear();
1299  insert_after(cbefore_begin(), __first, __last);
1300  }
1301 
1302  // Called by assign(size_type, const _Tp&) if Tp is CopyAssignable
1303  void
1304  _M_assign_n(size_type __n, const _Tp& __val, true_type)
1305  {
1306  auto __prev = before_begin();
1307  auto __curr = begin();
1308  auto __end = end();
1309  while (__curr != __end && __n > 0)
1310  {
1311  *__curr = __val;
1312  ++__prev;
1313  ++__curr;
1314  --__n;
1315  }
1316  if (__n > 0)
1317  insert_after(__prev, __n, __val);
1318  else if (__curr != __end)
1319  erase_after(__prev, __end);
1320  }
1321 
1322  // Called by assign(size_type, const _Tp&) if Tp is non-CopyAssignable
1323  void
1324  _M_assign_n(size_type __n, const _Tp& __val, false_type)
1325  {
1326  clear();
1327  insert_after(cbefore_begin(), __n, __val);
1328  }
1329  };
1330 
1331  /**
1332  * @brief Forward list equality comparison.
1333  * @param __lx A %forward_list
1334  * @param __ly A %forward_list of the same type as @a __lx.
1335  * @return True iff the elements of the forward lists are equal.
1336  *
1337  * This is an equivalence relation. It is linear in the number of
1338  * elements of the forward lists. Deques are considered equivalent
1339  * if corresponding elements compare equal.
1340  */
1341  template<typename _Tp, typename _Alloc>
1342  bool
1343  operator==(const forward_list<_Tp, _Alloc>& __lx,
1344  const forward_list<_Tp, _Alloc>& __ly);
1345 
1346  /**
1347  * @brief Forward list ordering relation.
1348  * @param __lx A %forward_list.
1349  * @param __ly A %forward_list of the same type as @a __lx.
1350  * @return True iff @a __lx is lexicographically less than @a __ly.
1351  *
1352  * This is a total ordering relation. It is linear in the number of
1353  * elements of the forward lists. The elements must be comparable
1354  * with @c <.
1355  *
1356  * See std::lexicographical_compare() for how the determination is made.
1357  */
1358  template<typename _Tp, typename _Alloc>
1359  inline bool
1360  operator<(const forward_list<_Tp, _Alloc>& __lx,
1361  const forward_list<_Tp, _Alloc>& __ly)
1362  { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
1363  __ly.cbegin(), __ly.cend()); }
1364 
1365  /// Based on operator==
1366  template<typename _Tp, typename _Alloc>
1367  inline bool
1368  operator!=(const forward_list<_Tp, _Alloc>& __lx,
1369  const forward_list<_Tp, _Alloc>& __ly)
1370  { return !(__lx == __ly); }
1371 
1372  /// Based on operator<
1373  template<typename _Tp, typename _Alloc>
1374  inline bool
1376  const forward_list<_Tp, _Alloc>& __ly)
1377  { return (__ly < __lx); }
1378 
1379  /// Based on operator<
1380  template<typename _Tp, typename _Alloc>
1381  inline bool
1383  const forward_list<_Tp, _Alloc>& __ly)
1384  { return !(__lx < __ly); }
1385 
1386  /// Based on operator<
1387  template<typename _Tp, typename _Alloc>
1388  inline bool
1389  operator<=(const forward_list<_Tp, _Alloc>& __lx,
1390  const forward_list<_Tp, _Alloc>& __ly)
1391  { return !(__ly < __lx); }
1392 
1393  /// See std::forward_list::swap().
1394  template<typename _Tp, typename _Alloc>
1395  inline void
1398  { __lx.swap(__ly); }
1399 
1400 _GLIBCXX_END_NAMESPACE_CONTAINER
1401 } // namespace std
1402 
1403 #endif // _FORWARD_LIST_H
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Definition: move.h:176
const_iterator cbegin() const noexcept
Definition: forward_list.h:707
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
Definition: forward_list.h:569
void reverse() noexcept
Reverse the elements in list.
iterator insert_after(const_iterator __pos, std::initializer_list< _Tp > __il)
Inserts the contents of an initializer_list into forward_list after the specified iterator...
Definition: forward_list.h:920
iterator end() noexcept
Definition: forward_list.h:689
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
Definition: forward_list.h:450
iterator emplace_after(const_iterator __pos, _Args &&...__args)
Constructs object in forward_list after the specified iterator.
Definition: forward_list.h:838
Uniform interface to C++98 and C++0x allocators.
reference front()
Definition: forward_list.h:750
bool empty() const noexcept
Definition: forward_list.h:733
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
const_iterator end() const noexcept
Definition: forward_list.h:698
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
Definition: forward_list.h:610
const_iterator cend() const noexcept
Definition: forward_list.h:725
bool operator>=(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string doesn't precede string.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
Forward iterators support a superset of input iterator operations.
forward_list(forward_list &&__list) noexcept
The forward_list move constructor.
Definition: forward_list.h:526
forward_list(const forward_list &__list)
The forward_list copy constructor.
Definition: forward_list.h:512
void merge(forward_list &&__list)
Merge sorted lists.
A forward_list::iterator.
Definition: forward_list.h:120
~forward_list() noexcept
The forward_list dtor.
Definition: forward_list.h:545
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
Definition: forward_list.h:537
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
Definition: forward_list.h:589
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last)
Insert range from another forward_list.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
bool operator>(const basic_string< _CharT, _Traits, _Alloc > &__lhs, const basic_string< _CharT, _Traits, _Alloc > &__rhs)
Test if string follows string.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
Definition: forward_list.h:485
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
Definition: forward_list.h:855
const_iterator before_begin() const noexcept
Definition: forward_list.h:663
void unique()
Remove consecutive duplicate elements.
A forward_list::const_iterator.
Definition: forward_list.h:187
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
Definition: forward_list.h:941
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
Definition: forward_list.h:627
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
Definition: forward_list.h:964
iterator before_begin() noexcept
Definition: forward_list.h:654
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
Definition: forward_list.h:472
void pop_front()
Removes first element.
Definition: forward_list.h:820
void emplace_front(_Args &&...__args)
Constructs object in forward_list at the front of the list.
Definition: forward_list.h:782
void swap(forward_list &__list) noexcept(_Node_alloc_traits::_S_nothrow_swap())
Swaps data with another forward_list.
Definition: forward_list.h:981
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
Definition: forward_list.h:53
forward_list(const _Alloc &__al=_Alloc())
Creates a forward_list with no elements.
Definition: forward_list.h:441
One of the comparison functors.
Definition: stl_function.h:352
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
Uniform interface to all pointer-like types.
Definition: ptr_traits.h:132
iterator begin() noexcept
Definition: forward_list.h:671
const_reference front() const
Definition: forward_list.h:761
void sort()
Sort the elements of the list.
Base class for forward_list.
Definition: forward_list.h:274
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
forward_list(forward_list &&__list, const _Alloc &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
Definition: forward_list.h:459
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
Definition: forward_list.h:409
const_iterator begin() const noexcept
Definition: forward_list.h:680
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Definition: forward_list.h:644
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
Definition: forward_list.h:797
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
Definition: forward_list.h:98
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition: move.h:47
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
Definition: forward_list.h:639
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
size_type max_size() const noexcept
Definition: forward_list.h:740
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
Definition: forward_list.h:502
ISO C++ entities toplevel namespace is std.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:101
void clear() noexcept
Erases all the elements.
const_iterator cbefore_begin() const noexcept
Definition: forward_list.h:716
One of the comparison functors.
Definition: stl_function.h:382