138fd1498Szrj // <forward_list.h> -*- C++ -*-
238fd1498Szrj
338fd1498Szrj // Copyright (C) 2008-2018 Free Software Foundation, Inc.
438fd1498Szrj //
538fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free
638fd1498Szrj // software; you can redistribute it and/or modify it under the
738fd1498Szrj // terms of the GNU General Public License as published by the
838fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
938fd1498Szrj // any later version.
1038fd1498Szrj
1138fd1498Szrj // This library is distributed in the hope that it will be useful,
1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1438fd1498Szrj // GNU General Public License for more details.
1538fd1498Szrj
1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
1838fd1498Szrj // 3.1, as published by the Free Software Foundation.
1938fd1498Szrj
2038fd1498Szrj // You should have received a copy of the GNU General Public License and
2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2338fd1498Szrj // <http://www.gnu.org/licenses/>.
2438fd1498Szrj
2538fd1498Szrj /** @file bits/forward_list.h
2638fd1498Szrj * This is an internal header file, included by other library headers.
2738fd1498Szrj * Do not attempt to use it directly. @headername{forward_list}
2838fd1498Szrj */
2938fd1498Szrj
3038fd1498Szrj #ifndef _FORWARD_LIST_H
3138fd1498Szrj #define _FORWARD_LIST_H 1
3238fd1498Szrj
3338fd1498Szrj #pragma GCC system_header
3438fd1498Szrj
3538fd1498Szrj #include <initializer_list>
3638fd1498Szrj #include <bits/stl_iterator_base_types.h>
3738fd1498Szrj #include <bits/stl_iterator.h>
3838fd1498Szrj #include <bits/stl_algobase.h>
3938fd1498Szrj #include <bits/stl_function.h>
4038fd1498Szrj #include <bits/allocator.h>
4138fd1498Szrj #include <ext/alloc_traits.h>
4238fd1498Szrj #include <ext/aligned_buffer.h>
4338fd1498Szrj
_GLIBCXX_VISIBILITY(default)4438fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
4538fd1498Szrj {
4638fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
4738fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
4838fd1498Szrj
4938fd1498Szrj /**
5038fd1498Szrj * @brief A helper basic node class for %forward_list.
5138fd1498Szrj * This is just a linked list with nothing inside it.
5238fd1498Szrj * There are purely list shuffling utility methods here.
5338fd1498Szrj */
5438fd1498Szrj struct _Fwd_list_node_base
5538fd1498Szrj {
5638fd1498Szrj _Fwd_list_node_base() = default;
5738fd1498Szrj _Fwd_list_node_base(_Fwd_list_node_base&& __x) noexcept
5838fd1498Szrj : _M_next(__x._M_next)
5938fd1498Szrj { __x._M_next = nullptr; }
6038fd1498Szrj
6138fd1498Szrj _Fwd_list_node_base(const _Fwd_list_node_base&) = delete;
6238fd1498Szrj _Fwd_list_node_base& operator=(const _Fwd_list_node_base&) = delete;
6338fd1498Szrj
6438fd1498Szrj _Fwd_list_node_base&
6538fd1498Szrj operator=(_Fwd_list_node_base&& __x) noexcept
6638fd1498Szrj {
6738fd1498Szrj _M_next = __x._M_next;
6838fd1498Szrj __x._M_next = nullptr;
6938fd1498Szrj return *this;
7038fd1498Szrj }
7138fd1498Szrj
7238fd1498Szrj _Fwd_list_node_base* _M_next = nullptr;
7338fd1498Szrj
7438fd1498Szrj _Fwd_list_node_base*
7538fd1498Szrj _M_transfer_after(_Fwd_list_node_base* __begin,
7638fd1498Szrj _Fwd_list_node_base* __end) noexcept
7738fd1498Szrj {
7838fd1498Szrj _Fwd_list_node_base* __keep = __begin->_M_next;
7938fd1498Szrj if (__end)
8038fd1498Szrj {
8138fd1498Szrj __begin->_M_next = __end->_M_next;
8238fd1498Szrj __end->_M_next = _M_next;
8338fd1498Szrj }
8438fd1498Szrj else
8538fd1498Szrj __begin->_M_next = nullptr;
8638fd1498Szrj _M_next = __keep;
8738fd1498Szrj return __end;
8838fd1498Szrj }
8938fd1498Szrj
9038fd1498Szrj void
9138fd1498Szrj _M_reverse_after() noexcept
9238fd1498Szrj {
9338fd1498Szrj _Fwd_list_node_base* __tail = _M_next;
9438fd1498Szrj if (!__tail)
9538fd1498Szrj return;
9638fd1498Szrj while (_Fwd_list_node_base* __temp = __tail->_M_next)
9738fd1498Szrj {
9838fd1498Szrj _Fwd_list_node_base* __keep = _M_next;
9938fd1498Szrj _M_next = __temp;
10038fd1498Szrj __tail->_M_next = __temp->_M_next;
10138fd1498Szrj _M_next->_M_next = __keep;
10238fd1498Szrj }
10338fd1498Szrj }
10438fd1498Szrj };
10538fd1498Szrj
10638fd1498Szrj /**
10738fd1498Szrj * @brief A helper node class for %forward_list.
10838fd1498Szrj * This is just a linked list with uninitialized storage for a
10938fd1498Szrj * data value in each node.
11038fd1498Szrj * There is a sorting utility method.
11138fd1498Szrj */
11238fd1498Szrj template<typename _Tp>
11338fd1498Szrj struct _Fwd_list_node
11438fd1498Szrj : public _Fwd_list_node_base
11538fd1498Szrj {
11638fd1498Szrj _Fwd_list_node() = default;
11738fd1498Szrj
11838fd1498Szrj __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
11938fd1498Szrj
12038fd1498Szrj _Tp*
12138fd1498Szrj _M_valptr() noexcept
12238fd1498Szrj { return _M_storage._M_ptr(); }
12338fd1498Szrj
12438fd1498Szrj const _Tp*
12538fd1498Szrj _M_valptr() const noexcept
12638fd1498Szrj { return _M_storage._M_ptr(); }
12738fd1498Szrj };
12838fd1498Szrj
12938fd1498Szrj /**
13038fd1498Szrj * @brief A forward_list::iterator.
13138fd1498Szrj *
13238fd1498Szrj * All the functions are op overloads.
13338fd1498Szrj */
13438fd1498Szrj template<typename _Tp>
13538fd1498Szrj struct _Fwd_list_iterator
13638fd1498Szrj {
13738fd1498Szrj typedef _Fwd_list_iterator<_Tp> _Self;
13838fd1498Szrj typedef _Fwd_list_node<_Tp> _Node;
13938fd1498Szrj
14038fd1498Szrj typedef _Tp value_type;
14138fd1498Szrj typedef _Tp* pointer;
14238fd1498Szrj typedef _Tp& reference;
14338fd1498Szrj typedef ptrdiff_t difference_type;
14438fd1498Szrj typedef std::forward_iterator_tag iterator_category;
14538fd1498Szrj
14638fd1498Szrj _Fwd_list_iterator() noexcept
14738fd1498Szrj : _M_node() { }
14838fd1498Szrj
14938fd1498Szrj explicit
15038fd1498Szrj _Fwd_list_iterator(_Fwd_list_node_base* __n) noexcept
15138fd1498Szrj : _M_node(__n) { }
15238fd1498Szrj
15338fd1498Szrj reference
15438fd1498Szrj operator*() const noexcept
15538fd1498Szrj { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
15638fd1498Szrj
15738fd1498Szrj pointer
15838fd1498Szrj operator->() const noexcept
15938fd1498Szrj { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
16038fd1498Szrj
16138fd1498Szrj _Self&
16238fd1498Szrj operator++() noexcept
16338fd1498Szrj {
16438fd1498Szrj _M_node = _M_node->_M_next;
16538fd1498Szrj return *this;
16638fd1498Szrj }
16738fd1498Szrj
16838fd1498Szrj _Self
16938fd1498Szrj operator++(int) noexcept
17038fd1498Szrj {
17138fd1498Szrj _Self __tmp(*this);
17238fd1498Szrj _M_node = _M_node->_M_next;
17338fd1498Szrj return __tmp;
17438fd1498Szrj }
17538fd1498Szrj
17638fd1498Szrj bool
17738fd1498Szrj operator==(const _Self& __x) const noexcept
17838fd1498Szrj { return _M_node == __x._M_node; }
17938fd1498Szrj
18038fd1498Szrj bool
18138fd1498Szrj operator!=(const _Self& __x) const noexcept
18238fd1498Szrj { return _M_node != __x._M_node; }
18338fd1498Szrj
18438fd1498Szrj _Self
18538fd1498Szrj _M_next() const noexcept
18638fd1498Szrj {
18738fd1498Szrj if (_M_node)
18838fd1498Szrj return _Fwd_list_iterator(_M_node->_M_next);
18938fd1498Szrj else
19038fd1498Szrj return _Fwd_list_iterator(nullptr);
19138fd1498Szrj }
19238fd1498Szrj
19338fd1498Szrj _Fwd_list_node_base* _M_node;
19438fd1498Szrj };
19538fd1498Szrj
19638fd1498Szrj /**
19738fd1498Szrj * @brief A forward_list::const_iterator.
19838fd1498Szrj *
19938fd1498Szrj * All the functions are op overloads.
20038fd1498Szrj */
20138fd1498Szrj template<typename _Tp>
20238fd1498Szrj struct _Fwd_list_const_iterator
20338fd1498Szrj {
20438fd1498Szrj typedef _Fwd_list_const_iterator<_Tp> _Self;
20538fd1498Szrj typedef const _Fwd_list_node<_Tp> _Node;
20638fd1498Szrj typedef _Fwd_list_iterator<_Tp> iterator;
20738fd1498Szrj
20838fd1498Szrj typedef _Tp value_type;
20938fd1498Szrj typedef const _Tp* pointer;
21038fd1498Szrj typedef const _Tp& reference;
21138fd1498Szrj typedef ptrdiff_t difference_type;
21238fd1498Szrj typedef std::forward_iterator_tag iterator_category;
21338fd1498Szrj
21438fd1498Szrj _Fwd_list_const_iterator() noexcept
21538fd1498Szrj : _M_node() { }
21638fd1498Szrj
21738fd1498Szrj explicit
21838fd1498Szrj _Fwd_list_const_iterator(const _Fwd_list_node_base* __n) noexcept
21938fd1498Szrj : _M_node(__n) { }
22038fd1498Szrj
22138fd1498Szrj _Fwd_list_const_iterator(const iterator& __iter) noexcept
22238fd1498Szrj : _M_node(__iter._M_node) { }
22338fd1498Szrj
22438fd1498Szrj reference
22538fd1498Szrj operator*() const noexcept
22638fd1498Szrj { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
22738fd1498Szrj
22838fd1498Szrj pointer
22938fd1498Szrj operator->() const noexcept
23038fd1498Szrj { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
23138fd1498Szrj
23238fd1498Szrj _Self&
23338fd1498Szrj operator++() noexcept
23438fd1498Szrj {
23538fd1498Szrj _M_node = _M_node->_M_next;
23638fd1498Szrj return *this;
23738fd1498Szrj }
23838fd1498Szrj
23938fd1498Szrj _Self
24038fd1498Szrj operator++(int) noexcept
24138fd1498Szrj {
24238fd1498Szrj _Self __tmp(*this);
24338fd1498Szrj _M_node = _M_node->_M_next;
24438fd1498Szrj return __tmp;
24538fd1498Szrj }
24638fd1498Szrj
24738fd1498Szrj bool
24838fd1498Szrj operator==(const _Self& __x) const noexcept
24938fd1498Szrj { return _M_node == __x._M_node; }
25038fd1498Szrj
25138fd1498Szrj bool
25238fd1498Szrj operator!=(const _Self& __x) const noexcept
25338fd1498Szrj { return _M_node != __x._M_node; }
25438fd1498Szrj
25538fd1498Szrj _Self
25638fd1498Szrj _M_next() const noexcept
25738fd1498Szrj {
25838fd1498Szrj if (this->_M_node)
25938fd1498Szrj return _Fwd_list_const_iterator(_M_node->_M_next);
26038fd1498Szrj else
26138fd1498Szrj return _Fwd_list_const_iterator(nullptr);
26238fd1498Szrj }
26338fd1498Szrj
26438fd1498Szrj const _Fwd_list_node_base* _M_node;
26538fd1498Szrj };
26638fd1498Szrj
26738fd1498Szrj /**
26838fd1498Szrj * @brief Forward list iterator equality comparison.
26938fd1498Szrj */
27038fd1498Szrj template<typename _Tp>
27138fd1498Szrj inline bool
27238fd1498Szrj operator==(const _Fwd_list_iterator<_Tp>& __x,
27338fd1498Szrj const _Fwd_list_const_iterator<_Tp>& __y) noexcept
27438fd1498Szrj { return __x._M_node == __y._M_node; }
27538fd1498Szrj
27638fd1498Szrj /**
27738fd1498Szrj * @brief Forward list iterator inequality comparison.
27838fd1498Szrj */
27938fd1498Szrj template<typename _Tp>
28038fd1498Szrj inline bool
28138fd1498Szrj operator!=(const _Fwd_list_iterator<_Tp>& __x,
28238fd1498Szrj const _Fwd_list_const_iterator<_Tp>& __y) noexcept
28338fd1498Szrj { return __x._M_node != __y._M_node; }
28438fd1498Szrj
28538fd1498Szrj /**
28638fd1498Szrj * @brief Base class for %forward_list.
28738fd1498Szrj */
28838fd1498Szrj template<typename _Tp, typename _Alloc>
28938fd1498Szrj struct _Fwd_list_base
29038fd1498Szrj {
29138fd1498Szrj protected:
29238fd1498Szrj typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
29338fd1498Szrj typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
29438fd1498Szrj
29538fd1498Szrj struct _Fwd_list_impl
29638fd1498Szrj : public _Node_alloc_type
29738fd1498Szrj {
29838fd1498Szrj _Fwd_list_node_base _M_head;
29938fd1498Szrj
30038fd1498Szrj _Fwd_list_impl()
301*58e805e6Szrj noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
30238fd1498Szrj : _Node_alloc_type(), _M_head()
30338fd1498Szrj { }
30438fd1498Szrj
30538fd1498Szrj _Fwd_list_impl(_Fwd_list_impl&&) = default;
30638fd1498Szrj
30738fd1498Szrj _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
30838fd1498Szrj : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
30938fd1498Szrj { }
31038fd1498Szrj
31138fd1498Szrj _Fwd_list_impl(_Node_alloc_type&& __a)
31238fd1498Szrj : _Node_alloc_type(std::move(__a)), _M_head()
31338fd1498Szrj { }
31438fd1498Szrj };
31538fd1498Szrj
31638fd1498Szrj _Fwd_list_impl _M_impl;
31738fd1498Szrj
31838fd1498Szrj public:
31938fd1498Szrj typedef _Fwd_list_iterator<_Tp> iterator;
32038fd1498Szrj typedef _Fwd_list_const_iterator<_Tp> const_iterator;
32138fd1498Szrj typedef _Fwd_list_node<_Tp> _Node;
32238fd1498Szrj
32338fd1498Szrj _Node_alloc_type&
32438fd1498Szrj _M_get_Node_allocator() noexcept
32538fd1498Szrj { return this->_M_impl; }
32638fd1498Szrj
32738fd1498Szrj const _Node_alloc_type&
32838fd1498Szrj _M_get_Node_allocator() const noexcept
32938fd1498Szrj { return this->_M_impl; }
33038fd1498Szrj
33138fd1498Szrj _Fwd_list_base() = default;
33238fd1498Szrj
33338fd1498Szrj _Fwd_list_base(_Node_alloc_type&& __a)
33438fd1498Szrj : _M_impl(std::move(__a)) { }
33538fd1498Szrj
33638fd1498Szrj // When allocators are always equal.
33738fd1498Szrj _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a,
33838fd1498Szrj std::true_type)
33938fd1498Szrj : _M_impl(std::move(__lst._M_impl), std::move(__a))
34038fd1498Szrj { }
34138fd1498Szrj
34238fd1498Szrj // When allocators are not always equal.
34338fd1498Szrj _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a);
34438fd1498Szrj
34538fd1498Szrj _Fwd_list_base(_Fwd_list_base&&) = default;
34638fd1498Szrj
34738fd1498Szrj ~_Fwd_list_base()
34838fd1498Szrj { _M_erase_after(&_M_impl._M_head, nullptr); }
34938fd1498Szrj
35038fd1498Szrj protected:
35138fd1498Szrj _Node*
35238fd1498Szrj _M_get_node()
35338fd1498Szrj {
35438fd1498Szrj auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
35538fd1498Szrj return std::__to_address(__ptr);
35638fd1498Szrj }
35738fd1498Szrj
35838fd1498Szrj template<typename... _Args>
35938fd1498Szrj _Node*
36038fd1498Szrj _M_create_node(_Args&&... __args)
36138fd1498Szrj {
36238fd1498Szrj _Node* __node = this->_M_get_node();
36338fd1498Szrj __try
36438fd1498Szrj {
36538fd1498Szrj ::new ((void*)__node) _Node;
366*58e805e6Szrj _Node_alloc_traits::construct(_M_get_Node_allocator(),
367*58e805e6Szrj __node->_M_valptr(),
36838fd1498Szrj std::forward<_Args>(__args)...);
36938fd1498Szrj }
37038fd1498Szrj __catch(...)
37138fd1498Szrj {
37238fd1498Szrj this->_M_put_node(__node);
37338fd1498Szrj __throw_exception_again;
37438fd1498Szrj }
37538fd1498Szrj return __node;
37638fd1498Szrj }
37738fd1498Szrj
37838fd1498Szrj template<typename... _Args>
37938fd1498Szrj _Fwd_list_node_base*
38038fd1498Szrj _M_insert_after(const_iterator __pos, _Args&&... __args);
38138fd1498Szrj
38238fd1498Szrj void
38338fd1498Szrj _M_put_node(_Node* __p)
38438fd1498Szrj {
38538fd1498Szrj typedef typename _Node_alloc_traits::pointer _Ptr;
38638fd1498Szrj auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__p);
38738fd1498Szrj _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
38838fd1498Szrj }
38938fd1498Szrj
39038fd1498Szrj _Fwd_list_node_base*
39138fd1498Szrj _M_erase_after(_Fwd_list_node_base* __pos);
39238fd1498Szrj
39338fd1498Szrj _Fwd_list_node_base*
39438fd1498Szrj _M_erase_after(_Fwd_list_node_base* __pos,
39538fd1498Szrj _Fwd_list_node_base* __last);
39638fd1498Szrj };
39738fd1498Szrj
39838fd1498Szrj /**
39938fd1498Szrj * @brief A standard container with linear time access to elements,
40038fd1498Szrj * and fixed time insertion/deletion at any point in the sequence.
40138fd1498Szrj *
40238fd1498Szrj * @ingroup sequences
40338fd1498Szrj *
40438fd1498Szrj * @tparam _Tp Type of element.
40538fd1498Szrj * @tparam _Alloc Allocator type, defaults to allocator<_Tp>.
40638fd1498Szrj *
40738fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, a
40838fd1498Szrj * <a href="tables.html#67">sequence</a>, including the
40938fd1498Szrj * <a href="tables.html#68">optional sequence requirements</a> with the
41038fd1498Szrj * %exception of @c at and @c operator[].
41138fd1498Szrj *
41238fd1498Szrj * This is a @e singly @e linked %list. Traversal up the
41338fd1498Szrj * %list requires linear time, but adding and removing elements (or
41438fd1498Szrj * @e nodes) is done in constant time, regardless of where the
41538fd1498Szrj * change takes place. Unlike std::vector and std::deque,
41638fd1498Szrj * random-access iterators are not provided, so subscripting ( @c
41738fd1498Szrj * [] ) access is not allowed. For algorithms which only need
41838fd1498Szrj * sequential access, this lack makes no difference.
41938fd1498Szrj *
42038fd1498Szrj * Also unlike the other standard containers, std::forward_list provides
42138fd1498Szrj * specialized algorithms %unique to linked lists, such as
42238fd1498Szrj * splicing, sorting, and in-place reversal.
42338fd1498Szrj */
42438fd1498Szrj template<typename _Tp, typename _Alloc = allocator<_Tp>>
42538fd1498Szrj class forward_list : private _Fwd_list_base<_Tp, _Alloc>
42638fd1498Szrj {
42738fd1498Szrj static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value,
42838fd1498Szrj "std::forward_list must have a non-const, non-volatile value_type");
42938fd1498Szrj #ifdef __STRICT_ANSI__
43038fd1498Szrj static_assert(is_same<typename _Alloc::value_type, _Tp>::value,
43138fd1498Szrj "std::forward_list must have the same value_type as its allocator");
43238fd1498Szrj #endif
43338fd1498Szrj
43438fd1498Szrj private:
43538fd1498Szrj typedef _Fwd_list_base<_Tp, _Alloc> _Base;
43638fd1498Szrj typedef _Fwd_list_node<_Tp> _Node;
43738fd1498Szrj typedef _Fwd_list_node_base _Node_base;
43838fd1498Szrj typedef typename _Base::_Node_alloc_type _Node_alloc_type;
43938fd1498Szrj typedef typename _Base::_Node_alloc_traits _Node_alloc_traits;
440*58e805e6Szrj typedef allocator_traits<__alloc_rebind<_Alloc, _Tp>> _Alloc_traits;
44138fd1498Szrj
44238fd1498Szrj public:
44338fd1498Szrj // types:
44438fd1498Szrj typedef _Tp value_type;
44538fd1498Szrj typedef typename _Alloc_traits::pointer pointer;
44638fd1498Szrj typedef typename _Alloc_traits::const_pointer const_pointer;
44738fd1498Szrj typedef value_type& reference;
44838fd1498Szrj typedef const value_type& const_reference;
44938fd1498Szrj
45038fd1498Szrj typedef _Fwd_list_iterator<_Tp> iterator;
45138fd1498Szrj typedef _Fwd_list_const_iterator<_Tp> const_iterator;
45238fd1498Szrj typedef std::size_t size_type;
45338fd1498Szrj typedef std::ptrdiff_t difference_type;
45438fd1498Szrj typedef _Alloc allocator_type;
45538fd1498Szrj
45638fd1498Szrj // 23.3.4.2 construct/copy/destroy:
45738fd1498Szrj
45838fd1498Szrj /**
45938fd1498Szrj * @brief Creates a %forward_list with no elements.
46038fd1498Szrj */
46138fd1498Szrj forward_list() = default;
46238fd1498Szrj
46338fd1498Szrj /**
46438fd1498Szrj * @brief Creates a %forward_list with no elements.
46538fd1498Szrj * @param __al An allocator object.
46638fd1498Szrj */
46738fd1498Szrj explicit
46838fd1498Szrj forward_list(const _Alloc& __al) noexcept
46938fd1498Szrj : _Base(_Node_alloc_type(__al))
47038fd1498Szrj { }
47138fd1498Szrj
47238fd1498Szrj /**
47338fd1498Szrj * @brief Copy constructor with allocator argument.
47438fd1498Szrj * @param __list Input list to copy.
47538fd1498Szrj * @param __al An allocator object.
47638fd1498Szrj */
47738fd1498Szrj forward_list(const forward_list& __list, const _Alloc& __al)
47838fd1498Szrj : _Base(_Node_alloc_type(__al))
47938fd1498Szrj { _M_range_initialize(__list.begin(), __list.end()); }
48038fd1498Szrj
48138fd1498Szrj private:
48238fd1498Szrj forward_list(forward_list&& __list, _Node_alloc_type&& __al,
48338fd1498Szrj false_type)
48438fd1498Szrj : _Base(std::move(__list), std::move(__al))
48538fd1498Szrj {
48638fd1498Szrj // If __list is not empty it means its allocator is not equal to __a,
48738fd1498Szrj // so we need to move from each element individually.
48838fd1498Szrj insert_after(cbefore_begin(),
48938fd1498Szrj std::__make_move_if_noexcept_iterator(__list.begin()),
49038fd1498Szrj std::__make_move_if_noexcept_iterator(__list.end()));
49138fd1498Szrj }
49238fd1498Szrj
49338fd1498Szrj forward_list(forward_list&& __list, _Node_alloc_type&& __al,
49438fd1498Szrj true_type)
49538fd1498Szrj noexcept
49638fd1498Szrj : _Base(std::move(__list), _Node_alloc_type(__al), true_type{})
49738fd1498Szrj { }
49838fd1498Szrj
49938fd1498Szrj public:
50038fd1498Szrj /**
50138fd1498Szrj * @brief Move constructor with allocator argument.
50238fd1498Szrj * @param __list Input list to move.
50338fd1498Szrj * @param __al An allocator object.
50438fd1498Szrj */
50538fd1498Szrj forward_list(forward_list&& __list, const _Alloc& __al)
50638fd1498Szrj noexcept(_Node_alloc_traits::_S_always_equal())
50738fd1498Szrj : forward_list(std::move(__list), _Node_alloc_type(__al),
50838fd1498Szrj typename _Node_alloc_traits::is_always_equal{})
50938fd1498Szrj { }
51038fd1498Szrj
51138fd1498Szrj /**
51238fd1498Szrj * @brief Creates a %forward_list with default constructed elements.
51338fd1498Szrj * @param __n The number of elements to initially create.
51438fd1498Szrj * @param __al An allocator object.
51538fd1498Szrj *
51638fd1498Szrj * This constructor creates the %forward_list with @a __n default
51738fd1498Szrj * constructed elements.
51838fd1498Szrj */
51938fd1498Szrj explicit
52038fd1498Szrj forward_list(size_type __n, const _Alloc& __al = _Alloc())
52138fd1498Szrj : _Base(_Node_alloc_type(__al))
52238fd1498Szrj { _M_default_initialize(__n); }
52338fd1498Szrj
52438fd1498Szrj /**
52538fd1498Szrj * @brief Creates a %forward_list with copies of an exemplar element.
52638fd1498Szrj * @param __n The number of elements to initially create.
52738fd1498Szrj * @param __value An element to copy.
52838fd1498Szrj * @param __al An allocator object.
52938fd1498Szrj *
53038fd1498Szrj * This constructor fills the %forward_list with @a __n copies of
53138fd1498Szrj * @a __value.
53238fd1498Szrj */
53338fd1498Szrj forward_list(size_type __n, const _Tp& __value,
53438fd1498Szrj const _Alloc& __al = _Alloc())
53538fd1498Szrj : _Base(_Node_alloc_type(__al))
53638fd1498Szrj { _M_fill_initialize(__n, __value); }
53738fd1498Szrj
53838fd1498Szrj /**
53938fd1498Szrj * @brief Builds a %forward_list from a range.
54038fd1498Szrj * @param __first An input iterator.
54138fd1498Szrj * @param __last An input iterator.
54238fd1498Szrj * @param __al An allocator object.
54338fd1498Szrj *
54438fd1498Szrj * Create a %forward_list consisting of copies of the elements from
54538fd1498Szrj * [@a __first,@a __last). This is linear in N (where N is
54638fd1498Szrj * distance(@a __first,@a __last)).
54738fd1498Szrj */
54838fd1498Szrj template<typename _InputIterator,
54938fd1498Szrj typename = std::_RequireInputIter<_InputIterator>>
55038fd1498Szrj forward_list(_InputIterator __first, _InputIterator __last,
55138fd1498Szrj const _Alloc& __al = _Alloc())
55238fd1498Szrj : _Base(_Node_alloc_type(__al))
55338fd1498Szrj { _M_range_initialize(__first, __last); }
55438fd1498Szrj
55538fd1498Szrj /**
55638fd1498Szrj * @brief The %forward_list copy constructor.
55738fd1498Szrj * @param __list A %forward_list of identical element and allocator
55838fd1498Szrj * types.
55938fd1498Szrj */
56038fd1498Szrj forward_list(const forward_list& __list)
56138fd1498Szrj : _Base(_Node_alloc_traits::_S_select_on_copy(
56238fd1498Szrj __list._M_get_Node_allocator()))
56338fd1498Szrj { _M_range_initialize(__list.begin(), __list.end()); }
56438fd1498Szrj
56538fd1498Szrj /**
56638fd1498Szrj * @brief The %forward_list move constructor.
56738fd1498Szrj * @param __list A %forward_list of identical element and allocator
56838fd1498Szrj * types.
56938fd1498Szrj *
57038fd1498Szrj * The newly-created %forward_list contains the exact contents of the
57138fd1498Szrj * moved instance. The contents of the moved instance are a valid, but
57238fd1498Szrj * unspecified %forward_list.
57338fd1498Szrj */
57438fd1498Szrj forward_list(forward_list&&) = default;
57538fd1498Szrj
57638fd1498Szrj /**
57738fd1498Szrj * @brief Builds a %forward_list from an initializer_list
57838fd1498Szrj * @param __il An initializer_list of value_type.
57938fd1498Szrj * @param __al An allocator object.
58038fd1498Szrj *
58138fd1498Szrj * Create a %forward_list consisting of copies of the elements
58238fd1498Szrj * in the initializer_list @a __il. This is linear in __il.size().
58338fd1498Szrj */
58438fd1498Szrj forward_list(std::initializer_list<_Tp> __il,
58538fd1498Szrj const _Alloc& __al = _Alloc())
58638fd1498Szrj : _Base(_Node_alloc_type(__al))
58738fd1498Szrj { _M_range_initialize(__il.begin(), __il.end()); }
58838fd1498Szrj
58938fd1498Szrj /**
59038fd1498Szrj * @brief The forward_list dtor.
59138fd1498Szrj */
59238fd1498Szrj ~forward_list() noexcept
59338fd1498Szrj { }
59438fd1498Szrj
59538fd1498Szrj /**
59638fd1498Szrj * @brief The %forward_list assignment operator.
59738fd1498Szrj * @param __list A %forward_list of identical element and allocator
59838fd1498Szrj * types.
59938fd1498Szrj *
60038fd1498Szrj * All the elements of @a __list are copied.
60138fd1498Szrj *
60238fd1498Szrj * Whether the allocator is copied depends on the allocator traits.
60338fd1498Szrj */
60438fd1498Szrj forward_list&
60538fd1498Szrj operator=(const forward_list& __list);
60638fd1498Szrj
60738fd1498Szrj /**
60838fd1498Szrj * @brief The %forward_list move assignment operator.
60938fd1498Szrj * @param __list A %forward_list of identical element and allocator
61038fd1498Szrj * types.
61138fd1498Szrj *
61238fd1498Szrj * The contents of @a __list are moved into this %forward_list
61338fd1498Szrj * (without copying, if the allocators permit it).
61438fd1498Szrj *
61538fd1498Szrj * Afterwards @a __list is a valid, but unspecified %forward_list
61638fd1498Szrj *
61738fd1498Szrj * Whether the allocator is moved depends on the allocator traits.
61838fd1498Szrj */
61938fd1498Szrj forward_list&
62038fd1498Szrj operator=(forward_list&& __list)
62138fd1498Szrj noexcept(_Node_alloc_traits::_S_nothrow_move())
62238fd1498Szrj {
62338fd1498Szrj constexpr bool __move_storage =
62438fd1498Szrj _Node_alloc_traits::_S_propagate_on_move_assign()
62538fd1498Szrj || _Node_alloc_traits::_S_always_equal();
62638fd1498Szrj _M_move_assign(std::move(__list), __bool_constant<__move_storage>());
62738fd1498Szrj return *this;
62838fd1498Szrj }
62938fd1498Szrj
63038fd1498Szrj /**
63138fd1498Szrj * @brief The %forward_list initializer list assignment operator.
63238fd1498Szrj * @param __il An initializer_list of value_type.
63338fd1498Szrj *
63438fd1498Szrj * Replace the contents of the %forward_list with copies of the
63538fd1498Szrj * elements in the initializer_list @a __il. This is linear in
63638fd1498Szrj * __il.size().
63738fd1498Szrj */
63838fd1498Szrj forward_list&
63938fd1498Szrj operator=(std::initializer_list<_Tp> __il)
64038fd1498Szrj {
64138fd1498Szrj assign(__il);
64238fd1498Szrj return *this;
64338fd1498Szrj }
64438fd1498Szrj
64538fd1498Szrj /**
64638fd1498Szrj * @brief Assigns a range to a %forward_list.
64738fd1498Szrj * @param __first An input iterator.
64838fd1498Szrj * @param __last An input iterator.
64938fd1498Szrj *
65038fd1498Szrj * This function fills a %forward_list with copies of the elements
65138fd1498Szrj * in the range [@a __first,@a __last).
65238fd1498Szrj *
65338fd1498Szrj * Note that the assignment completely changes the %forward_list and
65438fd1498Szrj * that the number of elements of the resulting %forward_list is the
65538fd1498Szrj * same as the number of elements assigned.
65638fd1498Szrj */
65738fd1498Szrj template<typename _InputIterator,
65838fd1498Szrj typename = std::_RequireInputIter<_InputIterator>>
65938fd1498Szrj void
66038fd1498Szrj assign(_InputIterator __first, _InputIterator __last)
66138fd1498Szrj {
66238fd1498Szrj typedef is_assignable<_Tp, decltype(*__first)> __assignable;
66338fd1498Szrj _M_assign(__first, __last, __assignable());
66438fd1498Szrj }
66538fd1498Szrj
66638fd1498Szrj /**
66738fd1498Szrj * @brief Assigns a given value to a %forward_list.
66838fd1498Szrj * @param __n Number of elements to be assigned.
66938fd1498Szrj * @param __val Value to be assigned.
67038fd1498Szrj *
67138fd1498Szrj * This function fills a %forward_list with @a __n copies of the
67238fd1498Szrj * given value. Note that the assignment completely changes the
67338fd1498Szrj * %forward_list, and that the resulting %forward_list has __n
67438fd1498Szrj * elements.
67538fd1498Szrj */
67638fd1498Szrj void
67738fd1498Szrj assign(size_type __n, const _Tp& __val)
67838fd1498Szrj { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
67938fd1498Szrj
68038fd1498Szrj /**
68138fd1498Szrj * @brief Assigns an initializer_list to a %forward_list.
68238fd1498Szrj * @param __il An initializer_list of value_type.
68338fd1498Szrj *
68438fd1498Szrj * Replace the contents of the %forward_list with copies of the
68538fd1498Szrj * elements in the initializer_list @a __il. This is linear in
68638fd1498Szrj * il.size().
68738fd1498Szrj */
68838fd1498Szrj void
68938fd1498Szrj assign(std::initializer_list<_Tp> __il)
69038fd1498Szrj { assign(__il.begin(), __il.end()); }
69138fd1498Szrj
69238fd1498Szrj /// Get a copy of the memory allocation object.
69338fd1498Szrj allocator_type
69438fd1498Szrj get_allocator() const noexcept
69538fd1498Szrj { return allocator_type(this->_M_get_Node_allocator()); }
69638fd1498Szrj
69738fd1498Szrj // 23.3.4.3 iterators:
69838fd1498Szrj
69938fd1498Szrj /**
70038fd1498Szrj * Returns a read/write iterator that points before the first element
70138fd1498Szrj * in the %forward_list. Iteration is done in ordinary element order.
70238fd1498Szrj */
70338fd1498Szrj iterator
70438fd1498Szrj before_begin() noexcept
70538fd1498Szrj { return iterator(&this->_M_impl._M_head); }
70638fd1498Szrj
70738fd1498Szrj /**
70838fd1498Szrj * Returns a read-only (constant) iterator that points before the
70938fd1498Szrj * first element in the %forward_list. Iteration is done in ordinary
71038fd1498Szrj * element order.
71138fd1498Szrj */
71238fd1498Szrj const_iterator
71338fd1498Szrj before_begin() const noexcept
71438fd1498Szrj { return const_iterator(&this->_M_impl._M_head); }
71538fd1498Szrj
71638fd1498Szrj /**
71738fd1498Szrj * Returns a read/write iterator that points to the first element
71838fd1498Szrj * in the %forward_list. Iteration is done in ordinary element order.
71938fd1498Szrj */
72038fd1498Szrj iterator
72138fd1498Szrj begin() noexcept
72238fd1498Szrj { return iterator(this->_M_impl._M_head._M_next); }
72338fd1498Szrj
72438fd1498Szrj /**
72538fd1498Szrj * Returns a read-only (constant) iterator that points to the first
72638fd1498Szrj * element in the %forward_list. Iteration is done in ordinary
72738fd1498Szrj * element order.
72838fd1498Szrj */
72938fd1498Szrj const_iterator
73038fd1498Szrj begin() const noexcept
73138fd1498Szrj { return const_iterator(this->_M_impl._M_head._M_next); }
73238fd1498Szrj
73338fd1498Szrj /**
73438fd1498Szrj * Returns a read/write iterator that points one past the last
73538fd1498Szrj * element in the %forward_list. Iteration is done in ordinary
73638fd1498Szrj * element order.
73738fd1498Szrj */
73838fd1498Szrj iterator
73938fd1498Szrj end() noexcept
74038fd1498Szrj { return iterator(nullptr); }
74138fd1498Szrj
74238fd1498Szrj /**
74338fd1498Szrj * Returns a read-only iterator that points one past the last
74438fd1498Szrj * element in the %forward_list. Iteration is done in ordinary
74538fd1498Szrj * element order.
74638fd1498Szrj */
74738fd1498Szrj const_iterator
74838fd1498Szrj end() const noexcept
74938fd1498Szrj { return const_iterator(nullptr); }
75038fd1498Szrj
75138fd1498Szrj /**
75238fd1498Szrj * Returns a read-only (constant) iterator that points to the
75338fd1498Szrj * first element in the %forward_list. Iteration is done in ordinary
75438fd1498Szrj * element order.
75538fd1498Szrj */
75638fd1498Szrj const_iterator
75738fd1498Szrj cbegin() const noexcept
75838fd1498Szrj { return const_iterator(this->_M_impl._M_head._M_next); }
75938fd1498Szrj
76038fd1498Szrj /**
76138fd1498Szrj * Returns a read-only (constant) iterator that points before the
76238fd1498Szrj * first element in the %forward_list. Iteration is done in ordinary
76338fd1498Szrj * element order.
76438fd1498Szrj */
76538fd1498Szrj const_iterator
76638fd1498Szrj cbefore_begin() const noexcept
76738fd1498Szrj { return const_iterator(&this->_M_impl._M_head); }
76838fd1498Szrj
76938fd1498Szrj /**
77038fd1498Szrj * Returns a read-only (constant) iterator that points one past
77138fd1498Szrj * the last element in the %forward_list. Iteration is done in
77238fd1498Szrj * ordinary element order.
77338fd1498Szrj */
77438fd1498Szrj const_iterator
77538fd1498Szrj cend() const noexcept
77638fd1498Szrj { return const_iterator(nullptr); }
77738fd1498Szrj
77838fd1498Szrj /**
77938fd1498Szrj * Returns true if the %forward_list is empty. (Thus begin() would
78038fd1498Szrj * equal end().)
78138fd1498Szrj */
78238fd1498Szrj bool
78338fd1498Szrj empty() const noexcept
78438fd1498Szrj { return this->_M_impl._M_head._M_next == nullptr; }
78538fd1498Szrj
78638fd1498Szrj /**
78738fd1498Szrj * Returns the largest possible number of elements of %forward_list.
78838fd1498Szrj */
78938fd1498Szrj size_type
79038fd1498Szrj max_size() const noexcept
79138fd1498Szrj { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
79238fd1498Szrj
79338fd1498Szrj // 23.3.4.4 element access:
79438fd1498Szrj
79538fd1498Szrj /**
79638fd1498Szrj * Returns a read/write reference to the data at the first
79738fd1498Szrj * element of the %forward_list.
79838fd1498Szrj */
79938fd1498Szrj reference
80038fd1498Szrj front()
80138fd1498Szrj {
80238fd1498Szrj _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
80338fd1498Szrj return *__front->_M_valptr();
80438fd1498Szrj }
80538fd1498Szrj
80638fd1498Szrj /**
80738fd1498Szrj * Returns a read-only (constant) reference to the data at the first
80838fd1498Szrj * element of the %forward_list.
80938fd1498Szrj */
81038fd1498Szrj const_reference
81138fd1498Szrj front() const
81238fd1498Szrj {
81338fd1498Szrj _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
81438fd1498Szrj return *__front->_M_valptr();
81538fd1498Szrj }
81638fd1498Szrj
81738fd1498Szrj // 23.3.4.5 modifiers:
81838fd1498Szrj
81938fd1498Szrj /**
82038fd1498Szrj * @brief Constructs object in %forward_list at the front of the
82138fd1498Szrj * list.
82238fd1498Szrj * @param __args Arguments.
82338fd1498Szrj *
82438fd1498Szrj * This function will insert an object of type Tp constructed
82538fd1498Szrj * with Tp(std::forward<Args>(args)...) at the front of the list
82638fd1498Szrj * Due to the nature of a %forward_list this operation can
82738fd1498Szrj * be done in constant time, and does not invalidate iterators
82838fd1498Szrj * and references.
82938fd1498Szrj */
83038fd1498Szrj template<typename... _Args>
83138fd1498Szrj #if __cplusplus > 201402L
83238fd1498Szrj reference
83338fd1498Szrj #else
83438fd1498Szrj void
83538fd1498Szrj #endif
83638fd1498Szrj emplace_front(_Args&&... __args)
83738fd1498Szrj {
83838fd1498Szrj this->_M_insert_after(cbefore_begin(),
83938fd1498Szrj std::forward<_Args>(__args)...);
84038fd1498Szrj #if __cplusplus > 201402L
84138fd1498Szrj return front();
84238fd1498Szrj #endif
84338fd1498Szrj }
84438fd1498Szrj
84538fd1498Szrj /**
84638fd1498Szrj * @brief Add data to the front of the %forward_list.
84738fd1498Szrj * @param __val Data to be added.
84838fd1498Szrj *
84938fd1498Szrj * This is a typical stack operation. The function creates an
85038fd1498Szrj * element at the front of the %forward_list and assigns the given
85138fd1498Szrj * data to it. Due to the nature of a %forward_list this operation
85238fd1498Szrj * can be done in constant time, and does not invalidate iterators
85338fd1498Szrj * and references.
85438fd1498Szrj */
85538fd1498Szrj void
85638fd1498Szrj push_front(const _Tp& __val)
85738fd1498Szrj { this->_M_insert_after(cbefore_begin(), __val); }
85838fd1498Szrj
85938fd1498Szrj /**
86038fd1498Szrj *
86138fd1498Szrj */
86238fd1498Szrj void
86338fd1498Szrj push_front(_Tp&& __val)
86438fd1498Szrj { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
86538fd1498Szrj
86638fd1498Szrj /**
86738fd1498Szrj * @brief Removes first element.
86838fd1498Szrj *
86938fd1498Szrj * This is a typical stack operation. It shrinks the %forward_list
87038fd1498Szrj * by one. Due to the nature of a %forward_list this operation can
87138fd1498Szrj * be done in constant time, and only invalidates iterators/references
87238fd1498Szrj * to the element being removed.
87338fd1498Szrj *
87438fd1498Szrj * Note that no data is returned, and if the first element's data
87538fd1498Szrj * is needed, it should be retrieved before pop_front() is
87638fd1498Szrj * called.
87738fd1498Szrj */
87838fd1498Szrj void
87938fd1498Szrj pop_front()
88038fd1498Szrj { this->_M_erase_after(&this->_M_impl._M_head); }
88138fd1498Szrj
88238fd1498Szrj /**
88338fd1498Szrj * @brief Constructs object in %forward_list after the specified
88438fd1498Szrj * iterator.
88538fd1498Szrj * @param __pos A const_iterator into the %forward_list.
88638fd1498Szrj * @param __args Arguments.
88738fd1498Szrj * @return An iterator that points to the inserted data.
88838fd1498Szrj *
88938fd1498Szrj * This function will insert an object of type T constructed
89038fd1498Szrj * with T(std::forward<Args>(args)...) after the specified
89138fd1498Szrj * location. Due to the nature of a %forward_list this operation can
89238fd1498Szrj * be done in constant time, and does not invalidate iterators
89338fd1498Szrj * and references.
89438fd1498Szrj */
89538fd1498Szrj template<typename... _Args>
89638fd1498Szrj iterator
89738fd1498Szrj emplace_after(const_iterator __pos, _Args&&... __args)
89838fd1498Szrj { return iterator(this->_M_insert_after(__pos,
89938fd1498Szrj std::forward<_Args>(__args)...)); }
90038fd1498Szrj
90138fd1498Szrj /**
90238fd1498Szrj * @brief Inserts given value into %forward_list after specified
90338fd1498Szrj * iterator.
90438fd1498Szrj * @param __pos An iterator into the %forward_list.
90538fd1498Szrj * @param __val Data to be inserted.
90638fd1498Szrj * @return An iterator that points to the inserted data.
90738fd1498Szrj *
90838fd1498Szrj * This function will insert a copy of the given value after
90938fd1498Szrj * the specified location. Due to the nature of a %forward_list this
91038fd1498Szrj * operation can be done in constant time, and does not
91138fd1498Szrj * invalidate iterators and references.
91238fd1498Szrj */
91338fd1498Szrj iterator
91438fd1498Szrj insert_after(const_iterator __pos, const _Tp& __val)
91538fd1498Szrj { return iterator(this->_M_insert_after(__pos, __val)); }
91638fd1498Szrj
91738fd1498Szrj /**
91838fd1498Szrj *
91938fd1498Szrj */
92038fd1498Szrj iterator
92138fd1498Szrj insert_after(const_iterator __pos, _Tp&& __val)
92238fd1498Szrj { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
92338fd1498Szrj
92438fd1498Szrj /**
92538fd1498Szrj * @brief Inserts a number of copies of given data into the
92638fd1498Szrj * %forward_list.
92738fd1498Szrj * @param __pos An iterator into the %forward_list.
92838fd1498Szrj * @param __n Number of elements to be inserted.
92938fd1498Szrj * @param __val Data to be inserted.
93038fd1498Szrj * @return An iterator pointing to the last inserted copy of
93138fd1498Szrj * @a val or @a pos if @a n == 0.
93238fd1498Szrj *
93338fd1498Szrj * This function will insert a specified number of copies of the
93438fd1498Szrj * given data after the location specified by @a pos.
93538fd1498Szrj *
93638fd1498Szrj * This operation is linear in the number of elements inserted and
93738fd1498Szrj * does not invalidate iterators and references.
93838fd1498Szrj */
93938fd1498Szrj iterator
94038fd1498Szrj insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
94138fd1498Szrj
94238fd1498Szrj /**
94338fd1498Szrj * @brief Inserts a range into the %forward_list.
94438fd1498Szrj * @param __pos An iterator into the %forward_list.
94538fd1498Szrj * @param __first An input iterator.
94638fd1498Szrj * @param __last An input iterator.
94738fd1498Szrj * @return An iterator pointing to the last inserted element or
94838fd1498Szrj * @a __pos if @a __first == @a __last.
94938fd1498Szrj *
95038fd1498Szrj * This function will insert copies of the data in the range
95138fd1498Szrj * [@a __first,@a __last) into the %forward_list after the
95238fd1498Szrj * location specified by @a __pos.
95338fd1498Szrj *
95438fd1498Szrj * This operation is linear in the number of elements inserted and
95538fd1498Szrj * does not invalidate iterators and references.
95638fd1498Szrj */
95738fd1498Szrj template<typename _InputIterator,
95838fd1498Szrj typename = std::_RequireInputIter<_InputIterator>>
95938fd1498Szrj iterator
96038fd1498Szrj insert_after(const_iterator __pos,
96138fd1498Szrj _InputIterator __first, _InputIterator __last);
96238fd1498Szrj
96338fd1498Szrj /**
96438fd1498Szrj * @brief Inserts the contents of an initializer_list into
96538fd1498Szrj * %forward_list after the specified iterator.
96638fd1498Szrj * @param __pos An iterator into the %forward_list.
96738fd1498Szrj * @param __il An initializer_list of value_type.
96838fd1498Szrj * @return An iterator pointing to the last inserted element
96938fd1498Szrj * or @a __pos if @a __il is empty.
97038fd1498Szrj *
97138fd1498Szrj * This function will insert copies of the data in the
97238fd1498Szrj * initializer_list @a __il into the %forward_list before the location
97338fd1498Szrj * specified by @a __pos.
97438fd1498Szrj *
97538fd1498Szrj * This operation is linear in the number of elements inserted and
97638fd1498Szrj * does not invalidate iterators and references.
97738fd1498Szrj */
97838fd1498Szrj iterator
97938fd1498Szrj insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
98038fd1498Szrj { return insert_after(__pos, __il.begin(), __il.end()); }
98138fd1498Szrj
98238fd1498Szrj /**
98338fd1498Szrj * @brief Removes the element pointed to by the iterator following
98438fd1498Szrj * @c pos.
98538fd1498Szrj * @param __pos Iterator pointing before element to be erased.
98638fd1498Szrj * @return An iterator pointing to the element following the one
98738fd1498Szrj * that was erased, or end() if no such element exists.
98838fd1498Szrj *
98938fd1498Szrj * This function will erase the element at the given position and
99038fd1498Szrj * thus shorten the %forward_list by one.
99138fd1498Szrj *
99238fd1498Szrj * Due to the nature of a %forward_list this operation can be done
99338fd1498Szrj * in constant time, and only invalidates iterators/references to
99438fd1498Szrj * the element being removed. The user is also cautioned that
99538fd1498Szrj * this function only erases the element, and that if the element
99638fd1498Szrj * is itself a pointer, the pointed-to memory is not touched in
99738fd1498Szrj * any way. Managing the pointer is the user's responsibility.
99838fd1498Szrj */
99938fd1498Szrj iterator
100038fd1498Szrj erase_after(const_iterator __pos)
100138fd1498Szrj { return iterator(this->_M_erase_after(const_cast<_Node_base*>
100238fd1498Szrj (__pos._M_node))); }
100338fd1498Szrj
100438fd1498Szrj /**
100538fd1498Szrj * @brief Remove a range of elements.
100638fd1498Szrj * @param __pos Iterator pointing before the first element to be
100738fd1498Szrj * erased.
100838fd1498Szrj * @param __last Iterator pointing to one past the last element to be
100938fd1498Szrj * erased.
101038fd1498Szrj * @return @ __last.
101138fd1498Szrj *
101238fd1498Szrj * This function will erase the elements in the range
101338fd1498Szrj * @a (__pos,__last) and shorten the %forward_list accordingly.
101438fd1498Szrj *
101538fd1498Szrj * This operation is linear time in the size of the range and only
101638fd1498Szrj * invalidates iterators/references to the element being removed.
101738fd1498Szrj * The user is also cautioned that this function only erases the
101838fd1498Szrj * elements, and that if the elements themselves are pointers, the
101938fd1498Szrj * pointed-to memory is not touched in any way. Managing the pointer
102038fd1498Szrj * is the user's responsibility.
102138fd1498Szrj */
102238fd1498Szrj iterator
102338fd1498Szrj erase_after(const_iterator __pos, const_iterator __last)
102438fd1498Szrj { return iterator(this->_M_erase_after(const_cast<_Node_base*>
102538fd1498Szrj (__pos._M_node),
102638fd1498Szrj const_cast<_Node_base*>
102738fd1498Szrj (__last._M_node))); }
102838fd1498Szrj
102938fd1498Szrj /**
103038fd1498Szrj * @brief Swaps data with another %forward_list.
103138fd1498Szrj * @param __list A %forward_list of the same element and allocator
103238fd1498Szrj * types.
103338fd1498Szrj *
103438fd1498Szrj * This exchanges the elements between two lists in constant
103538fd1498Szrj * time. Note that the global std::swap() function is
103638fd1498Szrj * specialized such that std::swap(l1,l2) will feed to this
103738fd1498Szrj * function.
103838fd1498Szrj *
103938fd1498Szrj * Whether the allocators are swapped depends on the allocator traits.
104038fd1498Szrj */
104138fd1498Szrj void
104238fd1498Szrj swap(forward_list& __list) noexcept
104338fd1498Szrj {
104438fd1498Szrj std::swap(this->_M_impl._M_head._M_next,
104538fd1498Szrj __list._M_impl._M_head._M_next);
104638fd1498Szrj _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
104738fd1498Szrj __list._M_get_Node_allocator());
104838fd1498Szrj }
104938fd1498Szrj
105038fd1498Szrj /**
105138fd1498Szrj * @brief Resizes the %forward_list to the specified number of
105238fd1498Szrj * elements.
105338fd1498Szrj * @param __sz Number of elements the %forward_list should contain.
105438fd1498Szrj *
105538fd1498Szrj * This function will %resize the %forward_list to the specified
105638fd1498Szrj * number of elements. If the number is smaller than the
105738fd1498Szrj * %forward_list's current number of elements the %forward_list
105838fd1498Szrj * is truncated, otherwise the %forward_list is extended and the
105938fd1498Szrj * new elements are default constructed.
106038fd1498Szrj */
106138fd1498Szrj void
106238fd1498Szrj resize(size_type __sz);
106338fd1498Szrj
106438fd1498Szrj /**
106538fd1498Szrj * @brief Resizes the %forward_list to the specified number of
106638fd1498Szrj * elements.
106738fd1498Szrj * @param __sz Number of elements the %forward_list should contain.
106838fd1498Szrj * @param __val Data with which new elements should be populated.
106938fd1498Szrj *
107038fd1498Szrj * This function will %resize the %forward_list to the specified
107138fd1498Szrj * number of elements. If the number is smaller than the
107238fd1498Szrj * %forward_list's current number of elements the %forward_list
107338fd1498Szrj * is truncated, otherwise the %forward_list is extended and new
107438fd1498Szrj * elements are populated with given data.
107538fd1498Szrj */
107638fd1498Szrj void
107738fd1498Szrj resize(size_type __sz, const value_type& __val);
107838fd1498Szrj
107938fd1498Szrj /**
108038fd1498Szrj * @brief Erases all the elements.
108138fd1498Szrj *
108238fd1498Szrj * Note that this function only erases
108338fd1498Szrj * the elements, and that if the elements themselves are
108438fd1498Szrj * pointers, the pointed-to memory is not touched in any way.
108538fd1498Szrj * Managing the pointer is the user's responsibility.
108638fd1498Szrj */
108738fd1498Szrj void
108838fd1498Szrj clear() noexcept
108938fd1498Szrj { this->_M_erase_after(&this->_M_impl._M_head, nullptr); }
109038fd1498Szrj
109138fd1498Szrj // 23.3.4.6 forward_list operations:
109238fd1498Szrj
109338fd1498Szrj /**
109438fd1498Szrj * @brief Insert contents of another %forward_list.
109538fd1498Szrj * @param __pos Iterator referencing the element to insert after.
109638fd1498Szrj * @param __list Source list.
109738fd1498Szrj *
109838fd1498Szrj * The elements of @a list are inserted in constant time after
109938fd1498Szrj * the element referenced by @a pos. @a list becomes an empty
110038fd1498Szrj * list.
110138fd1498Szrj *
110238fd1498Szrj * Requires this != @a x.
110338fd1498Szrj */
110438fd1498Szrj void
110538fd1498Szrj splice_after(const_iterator __pos, forward_list&& __list) noexcept
110638fd1498Szrj {
110738fd1498Szrj if (!__list.empty())
110838fd1498Szrj _M_splice_after(__pos, __list.before_begin(), __list.end());
110938fd1498Szrj }
111038fd1498Szrj
111138fd1498Szrj void
111238fd1498Szrj splice_after(const_iterator __pos, forward_list& __list) noexcept
111338fd1498Szrj { splice_after(__pos, std::move(__list)); }
111438fd1498Szrj
111538fd1498Szrj /**
111638fd1498Szrj * @brief Insert element from another %forward_list.
111738fd1498Szrj * @param __pos Iterator referencing the element to insert after.
111838fd1498Szrj * @param __list Source list.
111938fd1498Szrj * @param __i Iterator referencing the element before the element
112038fd1498Szrj * to move.
112138fd1498Szrj *
112238fd1498Szrj * Removes the element in list @a list referenced by @a i and
112338fd1498Szrj * inserts it into the current list after @a pos.
112438fd1498Szrj */
112538fd1498Szrj void
112638fd1498Szrj splice_after(const_iterator __pos, forward_list&& __list,
112738fd1498Szrj const_iterator __i) noexcept;
112838fd1498Szrj
112938fd1498Szrj void
113038fd1498Szrj splice_after(const_iterator __pos, forward_list& __list,
113138fd1498Szrj const_iterator __i) noexcept
113238fd1498Szrj { splice_after(__pos, std::move(__list), __i); }
113338fd1498Szrj
113438fd1498Szrj /**
113538fd1498Szrj * @brief Insert range from another %forward_list.
113638fd1498Szrj * @param __pos Iterator referencing the element to insert after.
113738fd1498Szrj * @param __list Source list.
113838fd1498Szrj * @param __before Iterator referencing before the start of range
113938fd1498Szrj * in list.
114038fd1498Szrj * @param __last Iterator referencing the end of range in list.
114138fd1498Szrj *
114238fd1498Szrj * Removes elements in the range (__before,__last) and inserts them
114338fd1498Szrj * after @a __pos in constant time.
114438fd1498Szrj *
114538fd1498Szrj * Undefined if @a __pos is in (__before,__last).
114638fd1498Szrj * @{
114738fd1498Szrj */
114838fd1498Szrj void
114938fd1498Szrj splice_after(const_iterator __pos, forward_list&&,
115038fd1498Szrj const_iterator __before, const_iterator __last) noexcept
115138fd1498Szrj { _M_splice_after(__pos, __before, __last); }
115238fd1498Szrj
115338fd1498Szrj void
115438fd1498Szrj splice_after(const_iterator __pos, forward_list&,
115538fd1498Szrj const_iterator __before, const_iterator __last) noexcept
115638fd1498Szrj { _M_splice_after(__pos, __before, __last); }
115738fd1498Szrj // @}
115838fd1498Szrj
115938fd1498Szrj /**
116038fd1498Szrj * @brief Remove all elements equal to value.
116138fd1498Szrj * @param __val The value to remove.
116238fd1498Szrj *
116338fd1498Szrj * Removes every element in the list equal to @a __val.
116438fd1498Szrj * Remaining elements stay in list order. Note that this
116538fd1498Szrj * function only erases the elements, and that if the elements
116638fd1498Szrj * themselves are pointers, the pointed-to memory is not
116738fd1498Szrj * touched in any way. Managing the pointer is the user's
116838fd1498Szrj * responsibility.
116938fd1498Szrj */
117038fd1498Szrj void
117138fd1498Szrj remove(const _Tp& __val);
117238fd1498Szrj
117338fd1498Szrj /**
117438fd1498Szrj * @brief Remove all elements satisfying a predicate.
117538fd1498Szrj * @param __pred Unary predicate function or object.
117638fd1498Szrj *
117738fd1498Szrj * Removes every element in the list for which the predicate
117838fd1498Szrj * returns true. Remaining elements stay in list order. Note
117938fd1498Szrj * that this function only erases the elements, and that if the
118038fd1498Szrj * elements themselves are pointers, the pointed-to memory is
118138fd1498Szrj * not touched in any way. Managing the pointer is the user's
118238fd1498Szrj * responsibility.
118338fd1498Szrj */
118438fd1498Szrj template<typename _Pred>
118538fd1498Szrj void
118638fd1498Szrj remove_if(_Pred __pred);
118738fd1498Szrj
118838fd1498Szrj /**
118938fd1498Szrj * @brief Remove consecutive duplicate elements.
119038fd1498Szrj *
119138fd1498Szrj * For each consecutive set of elements with the same value,
119238fd1498Szrj * remove all but the first one. Remaining elements stay in
119338fd1498Szrj * list order. Note that this function only erases the
119438fd1498Szrj * elements, and that if the elements themselves are pointers,
119538fd1498Szrj * the pointed-to memory is not touched in any way. Managing
119638fd1498Szrj * the pointer is the user's responsibility.
119738fd1498Szrj */
119838fd1498Szrj void
119938fd1498Szrj unique()
120038fd1498Szrj { unique(std::equal_to<_Tp>()); }
120138fd1498Szrj
120238fd1498Szrj /**
120338fd1498Szrj * @brief Remove consecutive elements satisfying a predicate.
120438fd1498Szrj * @param __binary_pred Binary predicate function or object.
120538fd1498Szrj *
120638fd1498Szrj * For each consecutive set of elements [first,last) that
120738fd1498Szrj * satisfy predicate(first,i) where i is an iterator in
120838fd1498Szrj * [first,last), remove all but the first one. Remaining
120938fd1498Szrj * elements stay in list order. Note that this function only
121038fd1498Szrj * erases the elements, and that if the elements themselves are
121138fd1498Szrj * pointers, the pointed-to memory is not touched in any way.
121238fd1498Szrj * Managing the pointer is the user's responsibility.
121338fd1498Szrj */
121438fd1498Szrj template<typename _BinPred>
121538fd1498Szrj void
121638fd1498Szrj unique(_BinPred __binary_pred);
121738fd1498Szrj
121838fd1498Szrj /**
121938fd1498Szrj * @brief Merge sorted lists.
122038fd1498Szrj * @param __list Sorted list to merge.
122138fd1498Szrj *
122238fd1498Szrj * Assumes that both @a list and this list are sorted according to
122338fd1498Szrj * operator<(). Merges elements of @a __list into this list in
122438fd1498Szrj * sorted order, leaving @a __list empty when complete. Elements in
122538fd1498Szrj * this list precede elements in @a __list that are equal.
122638fd1498Szrj */
122738fd1498Szrj void
122838fd1498Szrj merge(forward_list&& __list)
122938fd1498Szrj { merge(std::move(__list), std::less<_Tp>()); }
123038fd1498Szrj
123138fd1498Szrj void
123238fd1498Szrj merge(forward_list& __list)
123338fd1498Szrj { merge(std::move(__list)); }
123438fd1498Szrj
123538fd1498Szrj /**
123638fd1498Szrj * @brief Merge sorted lists according to comparison function.
123738fd1498Szrj * @param __list Sorted list to merge.
123838fd1498Szrj * @param __comp Comparison function defining sort order.
123938fd1498Szrj *
124038fd1498Szrj * Assumes that both @a __list and this list are sorted according to
124138fd1498Szrj * comp. Merges elements of @a __list into this list
124238fd1498Szrj * in sorted order, leaving @a __list empty when complete. Elements
124338fd1498Szrj * in this list precede elements in @a __list that are equivalent
124438fd1498Szrj * according to comp().
124538fd1498Szrj */
124638fd1498Szrj template<typename _Comp>
124738fd1498Szrj void
124838fd1498Szrj merge(forward_list&& __list, _Comp __comp);
124938fd1498Szrj
125038fd1498Szrj template<typename _Comp>
125138fd1498Szrj void
125238fd1498Szrj merge(forward_list& __list, _Comp __comp)
125338fd1498Szrj { merge(std::move(__list), __comp); }
125438fd1498Szrj
125538fd1498Szrj /**
125638fd1498Szrj * @brief Sort the elements of the list.
125738fd1498Szrj *
125838fd1498Szrj * Sorts the elements of this list in NlogN time. Equivalent
125938fd1498Szrj * elements remain in list order.
126038fd1498Szrj */
126138fd1498Szrj void
126238fd1498Szrj sort()
126338fd1498Szrj { sort(std::less<_Tp>()); }
126438fd1498Szrj
126538fd1498Szrj /**
126638fd1498Szrj * @brief Sort the forward_list using a comparison function.
126738fd1498Szrj *
126838fd1498Szrj * Sorts the elements of this list in NlogN time. Equivalent
126938fd1498Szrj * elements remain in list order.
127038fd1498Szrj */
127138fd1498Szrj template<typename _Comp>
127238fd1498Szrj void
127338fd1498Szrj sort(_Comp __comp);
127438fd1498Szrj
127538fd1498Szrj /**
127638fd1498Szrj * @brief Reverse the elements in list.
127738fd1498Szrj *
127838fd1498Szrj * Reverse the order of elements in the list in linear time.
127938fd1498Szrj */
128038fd1498Szrj void
128138fd1498Szrj reverse() noexcept
128238fd1498Szrj { this->_M_impl._M_head._M_reverse_after(); }
128338fd1498Szrj
128438fd1498Szrj private:
128538fd1498Szrj // Called by the range constructor to implement [23.3.4.2]/9
128638fd1498Szrj template<typename _InputIterator>
128738fd1498Szrj void
128838fd1498Szrj _M_range_initialize(_InputIterator __first, _InputIterator __last);
128938fd1498Szrj
129038fd1498Szrj // Called by forward_list(n,v,a), and the range constructor when it
129138fd1498Szrj // turns out to be the same thing.
129238fd1498Szrj void
129338fd1498Szrj _M_fill_initialize(size_type __n, const value_type& __value);
129438fd1498Szrj
129538fd1498Szrj // Called by splice_after and insert_after.
129638fd1498Szrj iterator
129738fd1498Szrj _M_splice_after(const_iterator __pos, const_iterator __before,
129838fd1498Szrj const_iterator __last);
129938fd1498Szrj
130038fd1498Szrj // Called by forward_list(n).
130138fd1498Szrj void
130238fd1498Szrj _M_default_initialize(size_type __n);
130338fd1498Szrj
130438fd1498Szrj // Called by resize(sz).
130538fd1498Szrj void
130638fd1498Szrj _M_default_insert_after(const_iterator __pos, size_type __n);
130738fd1498Szrj
130838fd1498Szrj // Called by operator=(forward_list&&)
130938fd1498Szrj void
131038fd1498Szrj _M_move_assign(forward_list&& __list, true_type) noexcept
131138fd1498Szrj {
131238fd1498Szrj clear();
131338fd1498Szrj this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
131438fd1498Szrj __list._M_impl._M_head._M_next = nullptr;
131538fd1498Szrj std::__alloc_on_move(this->_M_get_Node_allocator(),
131638fd1498Szrj __list._M_get_Node_allocator());
131738fd1498Szrj }
131838fd1498Szrj
131938fd1498Szrj // Called by operator=(forward_list&&)
132038fd1498Szrj void
132138fd1498Szrj _M_move_assign(forward_list&& __list, false_type)
132238fd1498Szrj {
132338fd1498Szrj if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
132438fd1498Szrj _M_move_assign(std::move(__list), true_type());
132538fd1498Szrj else
132638fd1498Szrj // The rvalue's allocator cannot be moved, or is not equal,
132738fd1498Szrj // so we need to individually move each element.
132838fd1498Szrj this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
132938fd1498Szrj std::__make_move_if_noexcept_iterator(__list.end()));
133038fd1498Szrj }
133138fd1498Szrj
133238fd1498Szrj // Called by assign(_InputIterator, _InputIterator) if _Tp is
133338fd1498Szrj // CopyAssignable.
133438fd1498Szrj template<typename _InputIterator>
133538fd1498Szrj void
133638fd1498Szrj _M_assign(_InputIterator __first, _InputIterator __last, true_type)
133738fd1498Szrj {
133838fd1498Szrj auto __prev = before_begin();
133938fd1498Szrj auto __curr = begin();
134038fd1498Szrj auto __end = end();
134138fd1498Szrj while (__curr != __end && __first != __last)
134238fd1498Szrj {
134338fd1498Szrj *__curr = *__first;
134438fd1498Szrj ++__prev;
134538fd1498Szrj ++__curr;
134638fd1498Szrj ++__first;
134738fd1498Szrj }
134838fd1498Szrj if (__first != __last)
134938fd1498Szrj insert_after(__prev, __first, __last);
135038fd1498Szrj else if (__curr != __end)
135138fd1498Szrj erase_after(__prev, __end);
135238fd1498Szrj }
135338fd1498Szrj
135438fd1498Szrj // Called by assign(_InputIterator, _InputIterator) if _Tp is not
135538fd1498Szrj // CopyAssignable.
135638fd1498Szrj template<typename _InputIterator>
135738fd1498Szrj void
135838fd1498Szrj _M_assign(_InputIterator __first, _InputIterator __last, false_type)
135938fd1498Szrj {
136038fd1498Szrj clear();
136138fd1498Szrj insert_after(cbefore_begin(), __first, __last);
136238fd1498Szrj }
136338fd1498Szrj
136438fd1498Szrj // Called by assign(size_type, const _Tp&) if Tp is CopyAssignable
136538fd1498Szrj void
136638fd1498Szrj _M_assign_n(size_type __n, const _Tp& __val, true_type)
136738fd1498Szrj {
136838fd1498Szrj auto __prev = before_begin();
136938fd1498Szrj auto __curr = begin();
137038fd1498Szrj auto __end = end();
137138fd1498Szrj while (__curr != __end && __n > 0)
137238fd1498Szrj {
137338fd1498Szrj *__curr = __val;
137438fd1498Szrj ++__prev;
137538fd1498Szrj ++__curr;
137638fd1498Szrj --__n;
137738fd1498Szrj }
137838fd1498Szrj if (__n > 0)
137938fd1498Szrj insert_after(__prev, __n, __val);
138038fd1498Szrj else if (__curr != __end)
138138fd1498Szrj erase_after(__prev, __end);
138238fd1498Szrj }
138338fd1498Szrj
138438fd1498Szrj // Called by assign(size_type, const _Tp&) if Tp is non-CopyAssignable
138538fd1498Szrj void
138638fd1498Szrj _M_assign_n(size_type __n, const _Tp& __val, false_type)
138738fd1498Szrj {
138838fd1498Szrj clear();
138938fd1498Szrj insert_after(cbefore_begin(), __n, __val);
139038fd1498Szrj }
139138fd1498Szrj };
139238fd1498Szrj
139338fd1498Szrj #if __cpp_deduction_guides >= 201606
139438fd1498Szrj template<typename _InputIterator, typename _ValT
139538fd1498Szrj = typename iterator_traits<_InputIterator>::value_type,
139638fd1498Szrj typename _Allocator = allocator<_ValT>,
139738fd1498Szrj typename = _RequireInputIter<_InputIterator>,
139838fd1498Szrj typename = _RequireAllocator<_Allocator>>
139938fd1498Szrj forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
140038fd1498Szrj -> forward_list<_ValT, _Allocator>;
140138fd1498Szrj #endif
140238fd1498Szrj
140338fd1498Szrj /**
140438fd1498Szrj * @brief Forward list equality comparison.
140538fd1498Szrj * @param __lx A %forward_list
140638fd1498Szrj * @param __ly A %forward_list of the same type as @a __lx.
140738fd1498Szrj * @return True iff the elements of the forward lists are equal.
140838fd1498Szrj *
140938fd1498Szrj * This is an equivalence relation. It is linear in the number of
141038fd1498Szrj * elements of the forward lists. Deques are considered equivalent
141138fd1498Szrj * if corresponding elements compare equal.
141238fd1498Szrj */
141338fd1498Szrj template<typename _Tp, typename _Alloc>
141438fd1498Szrj bool
141538fd1498Szrj operator==(const forward_list<_Tp, _Alloc>& __lx,
141638fd1498Szrj const forward_list<_Tp, _Alloc>& __ly);
141738fd1498Szrj
141838fd1498Szrj /**
141938fd1498Szrj * @brief Forward list ordering relation.
142038fd1498Szrj * @param __lx A %forward_list.
142138fd1498Szrj * @param __ly A %forward_list of the same type as @a __lx.
142238fd1498Szrj * @return True iff @a __lx is lexicographically less than @a __ly.
142338fd1498Szrj *
142438fd1498Szrj * This is a total ordering relation. It is linear in the number of
142538fd1498Szrj * elements of the forward lists. The elements must be comparable
142638fd1498Szrj * with @c <.
142738fd1498Szrj *
142838fd1498Szrj * See std::lexicographical_compare() for how the determination is made.
142938fd1498Szrj */
143038fd1498Szrj template<typename _Tp, typename _Alloc>
143138fd1498Szrj inline bool
143238fd1498Szrj operator<(const forward_list<_Tp, _Alloc>& __lx,
143338fd1498Szrj const forward_list<_Tp, _Alloc>& __ly)
143438fd1498Szrj { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
143538fd1498Szrj __ly.cbegin(), __ly.cend()); }
143638fd1498Szrj
143738fd1498Szrj /// Based on operator==
143838fd1498Szrj template<typename _Tp, typename _Alloc>
143938fd1498Szrj inline bool
144038fd1498Szrj operator!=(const forward_list<_Tp, _Alloc>& __lx,
144138fd1498Szrj const forward_list<_Tp, _Alloc>& __ly)
144238fd1498Szrj { return !(__lx == __ly); }
144338fd1498Szrj
144438fd1498Szrj /// Based on operator<
144538fd1498Szrj template<typename _Tp, typename _Alloc>
144638fd1498Szrj inline bool
144738fd1498Szrj operator>(const forward_list<_Tp, _Alloc>& __lx,
144838fd1498Szrj const forward_list<_Tp, _Alloc>& __ly)
144938fd1498Szrj { return (__ly < __lx); }
145038fd1498Szrj
145138fd1498Szrj /// Based on operator<
145238fd1498Szrj template<typename _Tp, typename _Alloc>
145338fd1498Szrj inline bool
145438fd1498Szrj operator>=(const forward_list<_Tp, _Alloc>& __lx,
145538fd1498Szrj const forward_list<_Tp, _Alloc>& __ly)
145638fd1498Szrj { return !(__lx < __ly); }
145738fd1498Szrj
145838fd1498Szrj /// Based on operator<
145938fd1498Szrj template<typename _Tp, typename _Alloc>
146038fd1498Szrj inline bool
146138fd1498Szrj operator<=(const forward_list<_Tp, _Alloc>& __lx,
146238fd1498Szrj const forward_list<_Tp, _Alloc>& __ly)
146338fd1498Szrj { return !(__ly < __lx); }
146438fd1498Szrj
146538fd1498Szrj /// See std::forward_list::swap().
146638fd1498Szrj template<typename _Tp, typename _Alloc>
146738fd1498Szrj inline void
146838fd1498Szrj swap(forward_list<_Tp, _Alloc>& __lx,
146938fd1498Szrj forward_list<_Tp, _Alloc>& __ly)
147038fd1498Szrj noexcept(noexcept(__lx.swap(__ly)))
147138fd1498Szrj { __lx.swap(__ly); }
147238fd1498Szrj
147338fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER
147438fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
147538fd1498Szrj } // namespace std
147638fd1498Szrj
147738fd1498Szrj #endif // _FORWARD_LIST_H
1478