libstdc++
forward_list.h
Go to the documentation of this file.
1// <forward_list.h> -*- C++ -*-
2
3// Copyright (C) 2008-2024 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#include <debug/assertions.h>
44
45namespace std _GLIBCXX_VISIBILITY(default)
46{
47_GLIBCXX_BEGIN_NAMESPACE_VERSION
48_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
49
50 /**
51 * @brief A helper basic node class for %forward_list.
52 * This is just a linked list with nothing inside it.
53 * There are purely list shuffling utility methods here.
54 */
56 {
57 _Fwd_list_node_base() = default;
59 : _M_next(__x._M_next)
60 { __x._M_next = nullptr; }
61
63 _Fwd_list_node_base& operator=(const _Fwd_list_node_base&) = delete;
64
66 operator=(_Fwd_list_node_base&& __x) noexcept
67 {
68 _M_next = __x._M_next;
69 __x._M_next = nullptr;
70 return *this;
71 }
72
73 _Fwd_list_node_base* _M_next = nullptr;
74
76 _M_transfer_after(_Fwd_list_node_base* __begin,
77 _Fwd_list_node_base* __end) noexcept
78 {
79 _Fwd_list_node_base* __keep = __begin->_M_next;
80 if (__end)
81 {
82 __begin->_M_next = __end->_M_next;
83 __end->_M_next = _M_next;
84 }
85 else
86 __begin->_M_next = nullptr;
87 _M_next = __keep;
88 return __end;
89 }
90
91 void
92 _M_reverse_after() noexcept
93 {
94 _Fwd_list_node_base* __tail = _M_next;
95 if (!__tail)
96 return;
97 while (_Fwd_list_node_base* __temp = __tail->_M_next)
98 {
99 _Fwd_list_node_base* __keep = _M_next;
100 _M_next = __temp;
101 __tail->_M_next = __temp->_M_next;
102 _M_next->_M_next = __keep;
103 }
104 }
105 };
106
107 /**
108 * @brief A helper node class for %forward_list.
109 * This is just a linked list with uninitialized storage for a
110 * data value in each node.
111 * There is a sorting utility method.
112 */
113 template<typename _Tp>
115 : public _Fwd_list_node_base
116 {
117 _Fwd_list_node() = default;
118
119 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
120
121 _Tp*
122 _M_valptr() noexcept
123 { return _M_storage._M_ptr(); }
124
125 const _Tp*
126 _M_valptr() const noexcept
127 { return _M_storage._M_ptr(); }
128 };
129
130 /**
131 * @brief A forward_list::iterator.
132 *
133 * All the functions are op overloads.
134 */
135 template<typename _Tp>
137 {
140
141 typedef _Tp value_type;
142 typedef _Tp* pointer;
143 typedef _Tp& reference;
146
147 _Fwd_list_iterator() noexcept
148 : _M_node() { }
149
150 explicit
152 : _M_node(__n) { }
153
154 [[__nodiscard__]]
155 reference
156 operator*() const noexcept
157 { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
158
159 [[__nodiscard__]]
160 pointer
161 operator->() const noexcept
162 { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
163
164 _Self&
165 operator++() noexcept
166 {
167 _M_node = _M_node->_M_next;
168 return *this;
169 }
170
171 _Self
172 operator++(int) noexcept
173 {
174 _Self __tmp(*this);
175 _M_node = _M_node->_M_next;
176 return __tmp;
177 }
178
179 /**
180 * @brief Forward list iterator equality comparison.
181 */
182 [[__nodiscard__]]
183 friend bool
184 operator==(const _Self& __x, const _Self& __y) noexcept
185 { return __x._M_node == __y._M_node; }
186
187#if __cpp_impl_three_way_comparison < 201907L
188 /**
189 * @brief Forward list iterator inequality comparison.
190 */
191 [[__nodiscard__]]
192 friend bool
193 operator!=(const _Self& __x, const _Self& __y) noexcept
194 { return __x._M_node != __y._M_node; }
195#endif
196
197 _Self
198 _M_next() const noexcept
199 {
200 if (_M_node)
201 return _Fwd_list_iterator(_M_node->_M_next);
202 else
203 return _Fwd_list_iterator(nullptr);
204 }
205
206 _Fwd_list_node_base* _M_node;
207 };
208
209 /**
210 * @brief A forward_list::const_iterator.
211 *
212 * All the functions are op overloads.
213 */
214 template<typename _Tp>
216 {
218 typedef const _Fwd_list_node<_Tp> _Node;
220
221 typedef _Tp value_type;
222 typedef const _Tp* pointer;
223 typedef const _Tp& reference;
226
227 _Fwd_list_const_iterator() noexcept
228 : _M_node() { }
229
230 explicit
232 : _M_node(__n) { }
233
234 _Fwd_list_const_iterator(const iterator& __iter) noexcept
235 : _M_node(__iter._M_node) { }
236
237 [[__nodiscard__]]
238 reference
239 operator*() const noexcept
240 { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
241
242 [[__nodiscard__]]
243 pointer
244 operator->() const noexcept
245 { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
246
247 _Self&
248 operator++() noexcept
249 {
250 _M_node = _M_node->_M_next;
251 return *this;
252 }
253
254 _Self
255 operator++(int) noexcept
256 {
257 _Self __tmp(*this);
258 _M_node = _M_node->_M_next;
259 return __tmp;
260 }
261
262 /**
263 * @brief Forward list const_iterator equality comparison.
264 */
265 [[__nodiscard__]]
266 friend bool
267 operator==(const _Self& __x, const _Self& __y) noexcept
268 { return __x._M_node == __y._M_node; }
269
270#if __cpp_impl_three_way_comparison < 201907L
271 /**
272 * @brief Forward list const_iterator inequality comparison.
273 */
274 [[__nodiscard__]]
275 friend bool
276 operator!=(const _Self& __x, const _Self& __y) noexcept
277 { return __x._M_node != __y._M_node; }
278#endif
279
280 _Self
281 _M_next() const noexcept
282 {
283 if (this->_M_node)
284 return _Fwd_list_const_iterator(_M_node->_M_next);
285 else
286 return _Fwd_list_const_iterator(nullptr);
287 }
288
289 const _Fwd_list_node_base* _M_node;
290 };
291
292 /**
293 * @brief Base class for %forward_list.
294 */
295 template<typename _Tp, typename _Alloc>
297 {
298 protected:
299 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
301
302 struct _Fwd_list_impl
303 : public _Node_alloc_type
304 {
305 _Fwd_list_node_base _M_head;
306
307 _Fwd_list_impl()
309 : _Node_alloc_type(), _M_head()
310 { }
311
312 _Fwd_list_impl(_Fwd_list_impl&&) = default;
313
314 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
315 : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
316 { }
317
318 _Fwd_list_impl(_Node_alloc_type&& __a)
319 : _Node_alloc_type(std::move(__a)), _M_head()
320 { }
321 };
322
323 _Fwd_list_impl _M_impl;
324
325 public:
329
330 _Node_alloc_type&
331 _M_get_Node_allocator() noexcept
332 { return this->_M_impl; }
333
334 const _Node_alloc_type&
335 _M_get_Node_allocator() const noexcept
336 { return this->_M_impl; }
337
338 _Fwd_list_base() = default;
339
340 _Fwd_list_base(_Node_alloc_type&& __a)
341 : _M_impl(std::move(__a)) { }
342
343 // When allocators are always equal.
344 _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a,
346 : _M_impl(std::move(__lst._M_impl), std::move(__a))
347 { }
348
349 // When allocators are not always equal.
350 _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a);
351
352 _Fwd_list_base(_Fwd_list_base&&) = default;
353
355 { _M_erase_after(&_M_impl._M_head, nullptr); }
356
357 protected:
358 _Node*
359 _M_get_node()
360 {
361 auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
362 return std::__to_address(__ptr);
363 }
364
365 template<typename... _Args>
366 _Node*
367 _M_create_node(_Args&&... __args)
368 {
369 _Node* __node = this->_M_get_node();
370 __try
371 {
372 ::new ((void*)__node) _Node;
373 _Node_alloc_traits::construct(_M_get_Node_allocator(),
374 __node->_M_valptr(),
376 }
377 __catch(...)
378 {
379 this->_M_put_node(__node);
380 __throw_exception_again;
381 }
382 return __node;
383 }
384
385 template<typename... _Args>
387 _M_insert_after(const_iterator __pos, _Args&&... __args);
388
389 void
390 _M_put_node(_Node* __p)
391 {
392 typedef typename _Node_alloc_traits::pointer _Ptr;
394 _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
395 }
396
398 _M_erase_after(_Fwd_list_node_base* __pos);
399
401 _M_erase_after(_Fwd_list_node_base* __pos,
402 _Fwd_list_node_base* __last);
403 };
404
405 /**
406 * @brief A standard container with linear time access to elements,
407 * and fixed time insertion/deletion at any point in the sequence.
408 *
409 * @ingroup sequences
410 * @headerfile forward_list
411 * @since C++11
412 *
413 * @tparam _Tp Type of element.
414 * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
415 *
416 * Meets the requirements of a <a href="tables.html#65">container</a>, a
417 * <a href="tables.html#67">sequence</a>, including the
418 * <a href="tables.html#68">optional sequence requirements</a> with the
419 * %exception of @c at and @c operator[].
420 *
421 * This is a @e singly @e linked %list. Traversal up the
422 * %list requires linear time, but adding and removing elements (or
423 * @e nodes) is done in constant time, regardless of where the
424 * change takes place. Unlike std::vector and std::deque,
425 * random-access iterators are not provided, so subscripting ( @c
426 * [] ) access is not allowed. For algorithms which only need
427 * sequential access, this lack makes no difference.
428 *
429 * Also unlike the other standard containers, std::forward_list provides
430 * specialized algorithms %unique to linked lists, such as
431 * splicing, sorting, and in-place reversal.
432 */
433 template<typename _Tp, typename _Alloc = allocator<_Tp>>
434 class forward_list : private _Fwd_list_base<_Tp, _Alloc>
435 {
436 static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value,
437 "std::forward_list must have a non-const, non-volatile value_type");
438#if __cplusplus > 201703L || defined __STRICT_ANSI__
440 "std::forward_list must have the same value_type as its allocator");
441#endif
442
443 private:
446 typedef typename _Base::_Node _Node;
450
451 public:
452 // types:
453 typedef _Tp value_type;
454 typedef typename _Alloc_traits::pointer pointer;
455 typedef typename _Alloc_traits::const_pointer const_pointer;
456 typedef value_type& reference;
457 typedef const value_type& const_reference;
458
459 typedef typename _Base::iterator iterator;
460 typedef typename _Base::const_iterator const_iterator;
461 typedef std::size_t size_type;
463 typedef _Alloc allocator_type;
464
465 // 23.3.4.2 construct/copy/destroy:
466
467 /**
468 * @brief Creates a %forward_list with no elements.
469 */
470 forward_list() = default;
471
472 /**
473 * @brief Creates a %forward_list with no elements.
474 * @param __al An allocator object.
475 */
476 explicit
477 forward_list(const _Alloc& __al) noexcept
479 { }
480
481 /**
482 * @brief Copy constructor with allocator argument.
483 * @param __list Input list to copy.
484 * @param __al An allocator object.
485 */
489 { _M_range_initialize(__list.begin(), __list.end()); }
490
491 private:
492 forward_list(forward_list&& __list, _Node_alloc_type&& __al,
494 : _Base(std::move(__list), std::move(__al))
495 {
496 // If __list is not empty it means its allocator is not equal to __a,
497 // so we need to move from each element individually.
499 std::__make_move_if_noexcept_iterator(__list.begin()),
500 std::__make_move_if_noexcept_iterator(__list.end()));
501 }
502
503 forward_list(forward_list&& __list, _Node_alloc_type&& __al,
504 true_type)
505 noexcept
506 : _Base(std::move(__list), _Node_alloc_type(__al), true_type{})
507 { }
508
509 public:
510 /**
511 * @brief Move constructor with allocator argument.
512 * @param __list Input list to move.
513 * @param __al An allocator object.
514 */
517 noexcept(_Node_alloc_traits::_S_always_equal())
519 typename _Node_alloc_traits::is_always_equal{})
520 { }
521
522 /**
523 * @brief Creates a %forward_list with default constructed elements.
524 * @param __n The number of elements to initially create.
525 * @param __al An allocator object.
526 *
527 * This constructor creates the %forward_list with @a __n default
528 * constructed elements.
529 */
530 explicit
531 forward_list(size_type __n, const _Alloc& __al = _Alloc())
533 { _M_default_initialize(__n); }
534
535 /**
536 * @brief Creates a %forward_list with copies of an exemplar element.
537 * @param __n The number of elements to initially create.
538 * @param __value An element to copy.
539 * @param __al An allocator object.
540 *
541 * This constructor fills the %forward_list with @a __n copies of
542 * @a __value.
543 */
544 forward_list(size_type __n, const _Tp& __value,
545 const _Alloc& __al = _Alloc())
547 { _M_fill_initialize(__n, __value); }
548
549 /**
550 * @brief Builds a %forward_list from a range.
551 * @param __first An input iterator.
552 * @param __last An input iterator.
553 * @param __al An allocator object.
554 *
555 * Create a %forward_list consisting of copies of the elements from
556 * [@a __first,@a __last). This is linear in N (where N is
557 * distance(@a __first,@a __last)).
558 */
559 template<typename _InputIterator,
562 const _Alloc& __al = _Alloc())
564 { _M_range_initialize(__first, __last); }
565
566 /**
567 * @brief The %forward_list copy constructor.
568 * @param __list A %forward_list of identical element and allocator
569 * types.
570 */
572 : _Base(_Node_alloc_traits::_S_select_on_copy(
573 __list._M_get_Node_allocator()))
574 { _M_range_initialize(__list.begin(), __list.end()); }
575
576 /**
577 * @brief The %forward_list move constructor.
578 * @param __list A %forward_list of identical element and allocator
579 * types.
580 *
581 * The newly-created %forward_list contains the exact contents of the
582 * moved instance. The contents of the moved instance are a valid, but
583 * unspecified %forward_list.
584 */
586
587 /**
588 * @brief Builds a %forward_list from an initializer_list
589 * @param __il An initializer_list of value_type.
590 * @param __al An allocator object.
591 *
592 * Create a %forward_list consisting of copies of the elements
593 * in the initializer_list @a __il. This is linear in __il.size().
594 */
596 const _Alloc& __al = _Alloc())
598 { _M_range_initialize(__il.begin(), __il.end()); }
599
600 /**
601 * @brief The forward_list dtor.
602 */
603 ~forward_list() noexcept
604 { }
605
606 /**
607 * @brief The %forward_list assignment operator.
608 * @param __list A %forward_list of identical element and allocator
609 * types.
610 *
611 * All the elements of @a __list are copied.
612 *
613 * Whether the allocator is copied depends on the allocator traits.
614 */
617
618 /**
619 * @brief The %forward_list move assignment operator.
620 * @param __list A %forward_list of identical element and allocator
621 * types.
622 *
623 * The contents of @a __list are moved into this %forward_list
624 * (without copying, if the allocators permit it).
625 *
626 * Afterwards @a __list is a valid, but unspecified %forward_list
627 *
628 * Whether the allocator is moved depends on the allocator traits.
629 */
632 noexcept(_Node_alloc_traits::_S_nothrow_move())
633 {
634 constexpr bool __move_storage =
635 _Node_alloc_traits::_S_propagate_on_move_assign()
636 || _Node_alloc_traits::_S_always_equal();
638 return *this;
639 }
640
641 /**
642 * @brief The %forward_list initializer list assignment operator.
643 * @param __il An initializer_list of value_type.
644 *
645 * Replace the contents of the %forward_list with copies of the
646 * elements in the initializer_list @a __il. This is linear in
647 * __il.size().
648 */
651 {
652 assign(__il);
653 return *this;
654 }
655
656 /**
657 * @brief Assigns a range to a %forward_list.
658 * @param __first An input iterator.
659 * @param __last An input iterator.
660 *
661 * This function fills a %forward_list with copies of the elements
662 * in the range [@a __first,@a __last).
663 *
664 * Note that the assignment completely changes the %forward_list and
665 * that the number of elements of the resulting %forward_list is the
666 * same as the number of elements assigned.
667 */
668 template<typename _InputIterator,
670 void
672 {
673 typedef is_assignable<_Tp, decltype(*__first)> __assignable;
674 _M_assign(__first, __last, __assignable());
675 }
676
677 /**
678 * @brief Assigns a given value to a %forward_list.
679 * @param __n Number of elements to be assigned.
680 * @param __val Value to be assigned.
681 *
682 * This function fills a %forward_list with @a __n copies of the
683 * given value. Note that the assignment completely changes the
684 * %forward_list, and that the resulting %forward_list has __n
685 * elements.
686 */
687 void
688 assign(size_type __n, const _Tp& __val)
689 { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
690
691 /**
692 * @brief Assigns an initializer_list to a %forward_list.
693 * @param __il An initializer_list of value_type.
694 *
695 * Replace the contents of the %forward_list with copies of the
696 * elements in the initializer_list @a __il. This is linear in
697 * il.size().
698 */
699 void
702
703 /// Get a copy of the memory allocation object.
704 allocator_type
706 { return allocator_type(this->_M_get_Node_allocator()); }
707
708 // 23.3.4.3 iterators:
709
710 /**
711 * Returns a read/write iterator that points before the first element
712 * in the %forward_list. Iteration is done in ordinary element order.
713 */
714 [[__nodiscard__]]
716 before_begin() noexcept
717 { return iterator(&this->_M_impl._M_head); }
718
719 /**
720 * Returns a read-only (constant) iterator that points before the
721 * first element in the %forward_list. Iteration is done in ordinary
722 * element order.
723 */
724 [[__nodiscard__]]
725 const_iterator
727 { return const_iterator(&this->_M_impl._M_head); }
728
729 /**
730 * Returns a read/write iterator that points to the first element
731 * in the %forward_list. Iteration is done in ordinary element order.
732 */
733 [[__nodiscard__]]
735 begin() noexcept
736 { return iterator(this->_M_impl._M_head._M_next); }
737
738 /**
739 * Returns a read-only (constant) iterator that points to the first
740 * element in the %forward_list. Iteration is done in ordinary
741 * element order.
742 */
743 [[__nodiscard__]]
744 const_iterator
745 begin() const noexcept
746 { return const_iterator(this->_M_impl._M_head._M_next); }
747
748 /**
749 * Returns a read/write iterator that points one past the last
750 * element in the %forward_list. Iteration is done in ordinary
751 * element order.
752 */
753 [[__nodiscard__]]
755 end() noexcept
756 { return iterator(nullptr); }
757
758 /**
759 * Returns a read-only iterator that points one past the last
760 * element in the %forward_list. Iteration is done in ordinary
761 * element order.
762 */
763 [[__nodiscard__]]
764 const_iterator
765 end() const noexcept
766 { return const_iterator(nullptr); }
767
768 /**
769 * Returns a read-only (constant) iterator that points to the
770 * first element in the %forward_list. Iteration is done in ordinary
771 * element order.
772 */
773 [[__nodiscard__]]
774 const_iterator
775 cbegin() const noexcept
776 { return const_iterator(this->_M_impl._M_head._M_next); }
777
778 /**
779 * Returns a read-only (constant) iterator that points before the
780 * first element in the %forward_list. Iteration is done in ordinary
781 * element order.
782 */
783 [[__nodiscard__]]
784 const_iterator
786 { return const_iterator(&this->_M_impl._M_head); }
787
788 /**
789 * Returns a read-only (constant) iterator that points one past
790 * the last element in the %forward_list. Iteration is done in
791 * ordinary element order.
792 */
793 [[__nodiscard__]]
794 const_iterator
795 cend() const noexcept
796 { return const_iterator(nullptr); }
797
798 /**
799 * Returns true if the %forward_list is empty. (Thus begin() would
800 * equal end().)
801 */
802 [[__nodiscard__]]
803 bool
804 empty() const noexcept
805 { return this->_M_impl._M_head._M_next == nullptr; }
806
807 /**
808 * Returns the largest possible number of elements of %forward_list.
809 */
810 [[__nodiscard__]]
811 size_type
812 max_size() const noexcept
813 { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
814
815 // 23.3.4.4 element access:
816
817 /**
818 * Returns a read/write reference to the data at the first
819 * element of the %forward_list.
820 */
821 [[__nodiscard__]]
822 reference
824 {
825 __glibcxx_requires_nonempty();
826 _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
827 return *__front->_M_valptr();
828 }
829
830 /**
831 * Returns a read-only (constant) reference to the data at the first
832 * element of the %forward_list.
833 */
834 [[__nodiscard__]]
835 const_reference
836 front() const
837 {
838 __glibcxx_requires_nonempty();
839 _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
840 return *__front->_M_valptr();
841 }
842
843 // 23.3.4.5 modifiers:
844
845 /**
846 * @brief Constructs object in %forward_list at the front of the
847 * list.
848 * @param __args Arguments.
849 *
850 * This function will insert an object of type Tp constructed
851 * with Tp(std::forward<Args>(args)...) at the front of the list
852 * Due to the nature of a %forward_list this operation can
853 * be done in constant time, and does not invalidate iterators
854 * and references.
855 */
856 template<typename... _Args>
857#if __cplusplus > 201402L
858 reference
859#else
860 void
861#endif
863 {
864 this->_M_insert_after(cbefore_begin(),
866#if __cplusplus > 201402L
867 return front();
868#endif
869 }
870
871 /**
872 * @brief Add data to the front of the %forward_list.
873 * @param __val Data to be added.
874 *
875 * This is a typical stack operation. The function creates an
876 * element at the front of the %forward_list and assigns the given
877 * data to it. Due to the nature of a %forward_list this operation
878 * can be done in constant time, and does not invalidate iterators
879 * and references.
880 */
881 void
882 push_front(const _Tp& __val)
883 { this->_M_insert_after(cbefore_begin(), __val); }
884
885 /**
886 *
887 */
888 void
889 push_front(_Tp&& __val)
890 { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
891
892 /**
893 * @brief Removes first element.
894 *
895 * This is a typical stack operation. It shrinks the %forward_list
896 * by one. Due to the nature of a %forward_list this operation can
897 * be done in constant time, and only invalidates iterators/references
898 * to the element being removed.
899 *
900 * Note that no data is returned, and if the first element's data
901 * is needed, it should be retrieved before pop_front() is
902 * called.
903 */
904 void
906 { this->_M_erase_after(&this->_M_impl._M_head); }
907
908 /**
909 * @brief Constructs object in %forward_list after the specified
910 * iterator.
911 * @param __pos A const_iterator into the %forward_list.
912 * @param __args Arguments.
913 * @return An iterator that points to the inserted data.
914 *
915 * This function will insert an object of type T constructed
916 * with T(std::forward<Args>(args)...) after the specified
917 * location. Due to the nature of a %forward_list this operation can
918 * be done in constant time, and does not invalidate iterators
919 * and references.
920 */
921 template<typename... _Args>
924 { return iterator(this->_M_insert_after(__pos,
926
927 /**
928 * @brief Inserts given value into %forward_list after specified
929 * iterator.
930 * @param __pos An iterator into the %forward_list.
931 * @param __val Data to be inserted.
932 * @return An iterator that points to the inserted data.
933 *
934 * This function will insert a copy of the given value after
935 * the specified location. Due to the nature of a %forward_list this
936 * operation can be done in constant time, and does not
937 * invalidate iterators and references.
938 */
941 { return iterator(this->_M_insert_after(__pos, __val)); }
942
943 /**
944 *
945 */
947 insert_after(const_iterator __pos, _Tp&& __val)
948 { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
949
950 /**
951 * @brief Inserts a number of copies of given data into the
952 * %forward_list.
953 * @param __pos An iterator into the %forward_list.
954 * @param __n Number of elements to be inserted.
955 * @param __val Data to be inserted.
956 * @return An iterator pointing to the last inserted copy of
957 * @a val or @a pos if @a n == 0.
958 *
959 * This function will insert a specified number of copies of the
960 * given data after the location specified by @a pos.
961 *
962 * This operation is linear in the number of elements inserted and
963 * does not invalidate iterators and references.
964 */
965 iterator
966 insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
967
968 /**
969 * @brief Inserts a range into the %forward_list.
970 * @param __pos An iterator into the %forward_list.
971 * @param __first An input iterator.
972 * @param __last An input iterator.
973 * @return An iterator pointing to the last inserted element or
974 * @a __pos if @a __first == @a __last.
975 *
976 * This function will insert copies of the data in the range
977 * [@a __first,@a __last) into the %forward_list after the
978 * location specified by @a __pos.
979 *
980 * This operation is linear in the number of elements inserted and
981 * does not invalidate iterators and references.
982 */
983 template<typename _InputIterator,
985 iterator
986 insert_after(const_iterator __pos,
987 _InputIterator __first, _InputIterator __last);
988
989 /**
990 * @brief Inserts the contents of an initializer_list into
991 * %forward_list after the specified iterator.
992 * @param __pos An iterator into the %forward_list.
993 * @param __il An initializer_list of value_type.
994 * @return An iterator pointing to the last inserted element
995 * or @a __pos if @a __il is empty.
996 *
997 * This function will insert copies of the data in the
998 * initializer_list @a __il into the %forward_list before the location
999 * specified by @a __pos.
1000 *
1001 * This operation is linear in the number of elements inserted and
1002 * does not invalidate iterators and references.
1003 */
1004 iterator
1007
1008 /**
1009 * @brief Removes the element pointed to by the iterator following
1010 * @c pos.
1011 * @param __pos Iterator pointing before element to be erased.
1012 * @return An iterator pointing to the element following the one
1013 * that was erased, or end() if no such element exists.
1014 *
1015 * This function will erase the element at the given position and
1016 * thus shorten the %forward_list by one.
1017 *
1018 * Due to the nature of a %forward_list this operation can be done
1019 * in constant time, and only invalidates iterators/references to
1020 * the element being removed. The user is also cautioned that
1021 * this function only erases the element, and that if the element
1022 * is itself a pointer, the pointed-to memory is not touched in
1023 * any way. Managing the pointer is the user's responsibility.
1024 */
1025 iterator
1027 { return iterator(this->_M_erase_after(const_cast<_Node_base*>
1028 (__pos._M_node))); }
1029
1030 /**
1031 * @brief Remove a range of elements.
1032 * @param __pos Iterator pointing before the first element to be
1033 * erased.
1034 * @param __last Iterator pointing to one past the last element to be
1035 * erased.
1036 * @return @ __last.
1037 *
1038 * This function will erase the elements in the range
1039 * @a (__pos,__last) and shorten the %forward_list accordingly.
1040 *
1041 * This operation is linear time in the size of the range and only
1042 * invalidates iterators/references to the element being removed.
1043 * The user is also cautioned that this function only erases the
1044 * elements, and that if the elements themselves are pointers, the
1045 * pointed-to memory is not touched in any way. Managing the pointer
1046 * is the user's responsibility.
1047 */
1048 iterator
1050 { return iterator(this->_M_erase_after(const_cast<_Node_base*>
1051 (__pos._M_node),
1052 const_cast<_Node_base*>
1053 (__last._M_node))); }
1054
1055 /**
1056 * @brief Swaps data with another %forward_list.
1057 * @param __list A %forward_list of the same element and allocator
1058 * types.
1059 *
1060 * This exchanges the elements between two lists in constant
1061 * time. Note that the global std::swap() function is
1062 * specialized such that std::swap(l1,l2) will feed to this
1063 * function.
1064 *
1065 * Whether the allocators are swapped depends on the allocator traits.
1066 */
1067 void
1069 {
1070 std::swap(this->_M_impl._M_head._M_next,
1071 __list._M_impl._M_head._M_next);
1072 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1073 __list._M_get_Node_allocator());
1074 }
1075
1076 /**
1077 * @brief Resizes the %forward_list to the specified number of
1078 * elements.
1079 * @param __sz Number of elements the %forward_list should contain.
1080 *
1081 * This function will %resize the %forward_list to the specified
1082 * number of elements. If the number is smaller than the
1083 * %forward_list's current number of elements the %forward_list
1084 * is truncated, otherwise the %forward_list is extended and the
1085 * new elements are default constructed.
1086 */
1087 void
1088 resize(size_type __sz);
1089
1090 /**
1091 * @brief Resizes the %forward_list to the specified number of
1092 * elements.
1093 * @param __sz Number of elements the %forward_list should contain.
1094 * @param __val Data with which new elements should be populated.
1095 *
1096 * This function will %resize the %forward_list to the specified
1097 * number of elements. If the number is smaller than the
1098 * %forward_list's current number of elements the %forward_list
1099 * is truncated, otherwise the %forward_list is extended and new
1100 * elements are populated with given data.
1101 */
1102 void
1103 resize(size_type __sz, const value_type& __val);
1104
1105 /**
1106 * @brief Erases all the elements.
1107 *
1108 * Note that this function only erases
1109 * the elements, and that if the elements themselves are
1110 * pointers, the pointed-to memory is not touched in any way.
1111 * Managing the pointer is the user's responsibility.
1112 */
1113 void
1114 clear() noexcept
1115 { this->_M_erase_after(&this->_M_impl._M_head, nullptr); }
1116
1117 // 23.3.4.6 forward_list operations:
1118
1119 /**
1120 * @brief Insert contents of another %forward_list.
1121 * @param __pos Iterator referencing the element to insert after.
1122 * @param __list Source list.
1123 *
1124 * The elements of @a list are inserted in constant time after
1125 * the element referenced by @a pos. @a list becomes an empty
1126 * list.
1127 *
1128 * Requires this != @a x.
1129 */
1130 void
1132 {
1133 if (!__list.empty())
1134 _M_splice_after(__pos, __list.before_begin(), __list.end());
1135 }
1136
1137 void
1138 splice_after(const_iterator __pos, forward_list& __list) noexcept
1140
1141 /**
1142 * @brief Insert element from another %forward_list.
1143 * @param __pos Iterator referencing the element to insert after.
1144 * @param __list Source list.
1145 * @param __i Iterator referencing the element before the element
1146 * to move.
1147 *
1148 * Removes the element in list @a list referenced by @a i and
1149 * inserts it into the current list after @a pos.
1150 */
1151 void
1152 splice_after(const_iterator __pos, forward_list&& __list,
1153 const_iterator __i) noexcept;
1154
1155 void
1156 splice_after(const_iterator __pos, forward_list& __list,
1157 const_iterator __i) noexcept
1158 { splice_after(__pos, std::move(__list), __i); }
1159
1160 /**
1161 * @brief Insert range from another %forward_list.
1162 * @param __pos Iterator referencing the element to insert after.
1163 * @param __list Source list.
1164 * @param __before Iterator referencing before the start of range
1165 * in list.
1166 * @param __last Iterator referencing the end of range in list.
1167 *
1168 * Removes elements in the range (__before,__last) and inserts them
1169 * after @a __pos in constant time.
1170 *
1171 * Undefined if @a __pos is in (__before,__last).
1172 * @{
1173 */
1174 void
1176 const_iterator __before, const_iterator __last) noexcept
1177 { _M_splice_after(__pos, __before, __last); }
1178
1179 void
1181 const_iterator __before, const_iterator __last) noexcept
1182 { _M_splice_after(__pos, __before, __last); }
1183 /// @}
1184
1185 private:
1186#ifdef __glibcxx_list_remove_return_type // C++20 && HOSTED
1187 using __remove_return_type = size_type;
1188# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
1189 __attribute__((__abi_tag__("__cxx20")))
1190#else
1191 using __remove_return_type = void;
1192# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1193#endif
1194 public:
1195
1196 /**
1197 * @brief Remove all elements equal to value.
1198 * @param __val The value to remove.
1199 *
1200 * Removes every element in the list equal to @a __val.
1201 * Remaining elements stay in list order. Note that this
1202 * function only erases the elements, and that if the elements
1203 * themselves are pointers, the pointed-to memory is not
1204 * touched in any way. Managing the pointer is the user's
1205 * responsibility.
1206 */
1207 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1208 __remove_return_type
1209 remove(const _Tp& __val);
1210
1211 /**
1212 * @brief Remove all elements satisfying a predicate.
1213 * @param __pred Unary predicate function or object.
1214 *
1215 * Removes every element in the list for which the predicate
1216 * returns true. Remaining elements stay in list order. Note
1217 * that this function only erases the elements, and that if the
1218 * elements themselves are pointers, the pointed-to memory is
1219 * not touched in any way. Managing the pointer is the user's
1220 * responsibility.
1221 */
1222 template<typename _Pred>
1223 __remove_return_type
1225
1226 /**
1227 * @brief Remove consecutive duplicate elements.
1228 *
1229 * For each consecutive set of elements with the same value,
1230 * remove all but the first one. Remaining elements stay in
1231 * list order. Note that this function only erases the
1232 * elements, and that if the elements themselves are pointers,
1233 * the pointed-to memory is not touched in any way. Managing
1234 * the pointer is the user's responsibility.
1235 */
1236 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1237 __remove_return_type
1239 { return unique(std::equal_to<_Tp>()); }
1240
1241#undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1242
1243 /**
1244 * @brief Remove consecutive elements satisfying a predicate.
1245 * @param __binary_pred Binary predicate function or object.
1246 *
1247 * For each consecutive set of elements [first,last) that
1248 * satisfy predicate(first,i) where i is an iterator in
1249 * [first,last), remove all but the first one. Remaining
1250 * elements stay in list order. Note that this function only
1251 * erases the elements, and that if the elements themselves are
1252 * pointers, the pointed-to memory is not touched in any way.
1253 * Managing the pointer is the user's responsibility.
1254 */
1255 template<typename _BinPred>
1256 __remove_return_type
1258
1259 /**
1260 * @brief Merge sorted lists.
1261 * @param __list Sorted list to merge.
1262 *
1263 * Assumes that both @a list and this list are sorted according to
1264 * operator<(). Merges elements of @a __list into this list in
1265 * sorted order, leaving @a __list empty when complete. Elements in
1266 * this list precede elements in @a __list that are equal.
1267 */
1268 void
1271
1272 void
1274 { merge(std::move(__list)); }
1275
1276 /**
1277 * @brief Merge sorted lists according to comparison function.
1278 * @param __list Sorted list to merge.
1279 * @param __comp Comparison function defining sort order.
1280 *
1281 * Assumes that both @a __list and this list are sorted according to
1282 * comp. Merges elements of @a __list into this list
1283 * in sorted order, leaving @a __list empty when complete. Elements
1284 * in this list precede elements in @a __list that are equivalent
1285 * according to comp().
1286 */
1287 template<typename _Comp>
1288 void
1289 merge(forward_list&& __list, _Comp __comp);
1290
1291 template<typename _Comp>
1292 void
1293 merge(forward_list& __list, _Comp __comp)
1294 { merge(std::move(__list), __comp); }
1295
1296 /**
1297 * @brief Sort the elements of the list.
1298 *
1299 * Sorts the elements of this list in NlogN time. Equivalent
1300 * elements remain in list order.
1301 */
1302 void
1304 { sort(std::less<_Tp>()); }
1305
1306 /**
1307 * @brief Sort the forward_list using a comparison function.
1308 *
1309 * Sorts the elements of this list in NlogN time. Equivalent
1310 * elements remain in list order.
1311 */
1312 template<typename _Comp>
1313 void
1314 sort(_Comp __comp);
1315
1316 /**
1317 * @brief Reverse the elements in list.
1318 *
1319 * Reverse the order of elements in the list in linear time.
1320 */
1321 void
1322 reverse() noexcept
1323 { this->_M_impl._M_head._M_reverse_after(); }
1324
1325 private:
1326 // Called by the range constructor to implement [23.3.4.2]/9
1327 template<typename _InputIterator>
1328 void
1329 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1330
1331 // Called by forward_list(n,v,a), and the range constructor when it
1332 // turns out to be the same thing.
1333 void
1334 _M_fill_initialize(size_type __n, const value_type& __value);
1335
1336 // Called by splice_after and insert_after.
1337 iterator
1338 _M_splice_after(const_iterator __pos, const_iterator __before,
1339 const_iterator __last);
1340
1341 // Called by forward_list(n).
1342 void
1343 _M_default_initialize(size_type __n);
1344
1345 // Called by resize(sz).
1346 void
1347 _M_default_insert_after(const_iterator __pos, size_type __n);
1348
1349 // Called by operator=(forward_list&&)
1350 void
1351 _M_move_assign(forward_list&& __list, true_type) noexcept
1352 {
1353 clear();
1354 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1355 __list._M_impl._M_head._M_next = nullptr;
1356 std::__alloc_on_move(this->_M_get_Node_allocator(),
1357 __list._M_get_Node_allocator());
1358 }
1359
1360 // Called by operator=(forward_list&&)
1361 void
1362 _M_move_assign(forward_list&& __list, false_type)
1363 {
1364 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1365 _M_move_assign(std::move(__list), true_type());
1366 else
1367 // The rvalue's allocator cannot be moved, or is not equal,
1368 // so we need to individually move each element.
1369 this->assign(std::make_move_iterator(__list.begin()),
1370 std::make_move_iterator(__list.end()));
1371 }
1372
1373 // Called by assign(_InputIterator, _InputIterator) if _Tp is
1374 // CopyAssignable.
1375 template<typename _InputIterator>
1376 void
1377 _M_assign(_InputIterator __first, _InputIterator __last, true_type)
1378 {
1379 auto __prev = before_begin();
1380 auto __curr = begin();
1381 auto __end = end();
1382 while (__curr != __end && __first != __last)
1383 {
1384 *__curr = *__first;
1385 ++__prev;
1386 ++__curr;
1387 ++__first;
1388 }
1389 if (__first != __last)
1390 insert_after(__prev, __first, __last);
1391 else if (__curr != __end)
1392 erase_after(__prev, __end);
1393 }
1394
1395 // Called by assign(_InputIterator, _InputIterator) if _Tp is not
1396 // CopyAssignable.
1397 template<typename _InputIterator>
1398 void
1399 _M_assign(_InputIterator __first, _InputIterator __last, false_type)
1400 {
1401 clear();
1402 insert_after(cbefore_begin(), __first, __last);
1403 }
1404
1405 // Called by assign(size_type, const _Tp&) if Tp is CopyAssignable
1406 void
1407 _M_assign_n(size_type __n, const _Tp& __val, true_type)
1408 {
1409 auto __prev = before_begin();
1410 auto __curr = begin();
1411 auto __end = end();
1412 while (__curr != __end && __n > 0)
1413 {
1414 *__curr = __val;
1415 ++__prev;
1416 ++__curr;
1417 --__n;
1418 }
1419 if (__n > 0)
1420 insert_after(__prev, __n, __val);
1421 else if (__curr != __end)
1422 erase_after(__prev, __end);
1423 }
1424
1425 // Called by assign(size_type, const _Tp&) if Tp is non-CopyAssignable
1426 void
1427 _M_assign_n(size_type __n, const _Tp& __val, false_type)
1428 {
1429 clear();
1430 insert_after(cbefore_begin(), __n, __val);
1431 }
1432 };
1433
1434#if __cpp_deduction_guides >= 201606
1435 template<typename _InputIterator, typename _ValT
1436 = typename iterator_traits<_InputIterator>::value_type,
1437 typename _Allocator = allocator<_ValT>,
1438 typename = _RequireInputIter<_InputIterator>,
1439 typename = _RequireAllocator<_Allocator>>
1440 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1441 -> forward_list<_ValT, _Allocator>;
1442#endif
1443
1444 /**
1445 * @brief Forward list equality comparison.
1446 * @param __lx A %forward_list
1447 * @param __ly A %forward_list of the same type as @a __lx.
1448 * @return True iff the elements of the forward lists are equal.
1449 *
1450 * This is an equivalence relation. It is linear in the number of
1451 * elements of the forward lists. Deques are considered equivalent
1452 * if corresponding elements compare equal.
1453 */
1454 template<typename _Tp, typename _Alloc>
1455 [[__nodiscard__]]
1456 bool
1459
1460#if __cpp_lib_three_way_comparison
1461 /**
1462 * @brief Forward list ordering relation.
1463 * @param __x A `forward_list`.
1464 * @param __y A `forward_list` of the same type as `__x`.
1465 * @return A value indicating whether `__x` is less than, equal to,
1466 * greater than, or incomparable with `__y`.
1467 *
1468 * See `std::lexicographical_compare_three_way()` for how the determination
1469 * is made. This operator is used to synthesize relational operators like
1470 * `<` and `>=` etc.
1471 */
1472 template<typename _Tp, typename _Alloc>
1473 [[nodiscard]]
1474 inline __detail::__synth3way_t<_Tp>
1475 operator<=>(const forward_list<_Tp, _Alloc>& __x,
1476 const forward_list<_Tp, _Alloc>& __y)
1477 {
1478 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
1479 __y.begin(), __y.end(),
1480 __detail::__synth3way);
1481 }
1482#else
1483 /**
1484 * @brief Forward list ordering relation.
1485 * @param __lx A %forward_list.
1486 * @param __ly A %forward_list of the same type as @a __lx.
1487 * @return True iff @a __lx is lexicographically less than @a __ly.
1488 *
1489 * This is a total ordering relation. It is linear in the number of
1490 * elements of the forward lists. The elements must be comparable
1491 * with @c <.
1492 *
1493 * See std::lexicographical_compare() for how the determination is made.
1494 */
1495 template<typename _Tp, typename _Alloc>
1496 [[__nodiscard__]]
1497 inline bool
1498 operator<(const forward_list<_Tp, _Alloc>& __lx,
1499 const forward_list<_Tp, _Alloc>& __ly)
1500 { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
1501 __ly.cbegin(), __ly.cend()); }
1502
1503 /// Based on operator==
1504 template<typename _Tp, typename _Alloc>
1505 [[__nodiscard__]]
1506 inline bool
1507 operator!=(const forward_list<_Tp, _Alloc>& __lx,
1508 const forward_list<_Tp, _Alloc>& __ly)
1509 { return !(__lx == __ly); }
1510
1511 /// Based on operator<
1512 template<typename _Tp, typename _Alloc>
1513 [[__nodiscard__]]
1514 inline bool
1515 operator>(const forward_list<_Tp, _Alloc>& __lx,
1516 const forward_list<_Tp, _Alloc>& __ly)
1517 { return (__ly < __lx); }
1518
1519 /// Based on operator<
1520 template<typename _Tp, typename _Alloc>
1521 [[__nodiscard__]]
1522 inline bool
1523 operator>=(const forward_list<_Tp, _Alloc>& __lx,
1524 const forward_list<_Tp, _Alloc>& __ly)
1525 { return !(__lx < __ly); }
1526
1527 /// Based on operator<
1528 template<typename _Tp, typename _Alloc>
1529 [[__nodiscard__]]
1530 inline bool
1531 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1532 const forward_list<_Tp, _Alloc>& __ly)
1533 { return !(__ly < __lx); }
1534#endif // three-way comparison
1535
1536 /// See std::forward_list::swap().
1537 template<typename _Tp, typename _Alloc>
1538 inline void
1541 noexcept(noexcept(__lx.swap(__ly)))
1542 { __lx.swap(__ly); }
1543
1544_GLIBCXX_END_NAMESPACE_CONTAINER
1545_GLIBCXX_END_NAMESPACE_VERSION
1546} // namespace std
1547
1548#endif // _FORWARD_LIST_H
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:855
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:869
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
Definition chrono.h:862
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
Definition type_traits:111
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
Definition type_traits:114
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:137
constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
ISO C++ entities toplevel namespace is std.
is_nothrow_default_constructible
Definition type_traits:1194
is_assignable
Definition type_traits:1226
A helper basic node class for forward_list. This is just a linked list with nothing inside it....
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
A forward_list::iterator.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list iterator equality comparison.
A forward_list::const_iterator.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list const_iterator equality comparison.
Base class for forward_list.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
__remove_return_type unique(_BinPred __binary_pred)
Remove consecutive elements satisfying a predicate.
iterator begin() noexcept
const_iterator before_begin() const noexcept
void reverse() noexcept
Reverse the elements in list.
forward_list()=default
Creates a forward_list with no elements.
~forward_list() noexcept
The forward_list dtor.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
void swap(forward_list &__list) noexcept
Swaps data with another forward_list.
const_reference front() const
void merge(forward_list &&__list)
Merge sorted lists.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
void sort()
Sort the elements of the list.
iterator before_begin() noexcept
forward_list(const forward_list &__list, const __type_identity_t< _Alloc > &__al)
Copy constructor with allocator argument.
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.
forward_list(const forward_list &__list)
The forward_list copy constructor.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
__remove_return_type remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
iterator end() noexcept
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
const_iterator begin() const noexcept
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
const_iterator cbefore_begin() const noexcept
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
reference emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
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.
const_iterator end() const noexcept
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
reference front()
forward_list(forward_list &&__list, const __type_identity_t< _Alloc > &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
__remove_return_type unique()
Remove consecutive duplicate elements.
void clear() noexcept
Erases all the elements.
__remove_return_type remove(const _Tp &__val)
Remove all elements equal to value.
const_iterator cend() const noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
bool empty() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
forward_list(forward_list &&)=default
The forward_list move constructor.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
void splice_after(const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
const_iterator cbegin() const noexcept
void pop_front()
Removes first element.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
size_type max_size() const noexcept
Uniform interface to all pointer-like types.
Definition ptr_traits.h:178
Forward iterators support a superset of input iterator operations.
Common iterator class.
Uniform interface to C++98 and C++11 allocators.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.