2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_FORWARD_LIST
|
|
|
|
#define _LIBCPP_FORWARD_LIST
|
|
|
|
|
|
|
|
/*
|
|
|
|
forward_list synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
template <class T, class Allocator = allocator<T>>
|
|
|
|
class forward_list
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T value_type;
|
|
|
|
typedef Allocator allocator_type;
|
|
|
|
|
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
typedef typename allocator_traits<allocator_type>::pointer pointer;
|
|
|
|
typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
|
|
|
|
typedef typename allocator_traits<allocator_type>::size_type size_type;
|
|
|
|
typedef typename allocator_traits<allocator_type>::difference_type difference_type;
|
|
|
|
|
|
|
|
typedef <details> iterator;
|
|
|
|
typedef <details> const_iterator;
|
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
forward_list()
|
|
|
|
noexcept(is_nothrow_default_constructible<allocator_type>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit forward_list(const allocator_type& a);
|
|
|
|
explicit forward_list(size_type n);
|
2013-09-10 02:19:45 +08:00
|
|
|
explicit forward_list(size_type n, const allocator_type& a); // C++14
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list(size_type n, const value_type& v);
|
|
|
|
forward_list(size_type n, const value_type& v, const allocator_type& a);
|
|
|
|
template <class InputIterator>
|
|
|
|
forward_list(InputIterator first, InputIterator last);
|
|
|
|
template <class InputIterator>
|
|
|
|
forward_list(InputIterator first, InputIterator last, const allocator_type& a);
|
|
|
|
forward_list(const forward_list& x);
|
|
|
|
forward_list(const forward_list& x, const allocator_type& a);
|
2011-06-04 00:20:53 +08:00
|
|
|
forward_list(forward_list&& x)
|
|
|
|
noexcept(is_nothrow_move_constructible<allocator_type>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list(forward_list&& x, const allocator_type& a);
|
|
|
|
forward_list(initializer_list<value_type> il);
|
|
|
|
forward_list(initializer_list<value_type> il, const allocator_type& a);
|
|
|
|
|
|
|
|
~forward_list();
|
|
|
|
|
|
|
|
forward_list& operator=(const forward_list& x);
|
2011-06-04 00:20:53 +08:00
|
|
|
forward_list& operator=(forward_list&& x)
|
|
|
|
noexcept(
|
|
|
|
allocator_type::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<allocator_type>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list& operator=(initializer_list<value_type> il);
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
void assign(InputIterator first, InputIterator last);
|
|
|
|
void assign(size_type n, const value_type& v);
|
|
|
|
void assign(initializer_list<value_type> il);
|
|
|
|
|
2011-06-03 00:44:28 +08:00
|
|
|
allocator_type get_allocator() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 00:44:28 +08:00
|
|
|
iterator begin() noexcept;
|
|
|
|
const_iterator begin() const noexcept;
|
|
|
|
iterator end() noexcept;
|
|
|
|
const_iterator end() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator cbegin() const noexcept;
|
|
|
|
const_iterator cend() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 00:44:28 +08:00
|
|
|
iterator before_begin() noexcept;
|
|
|
|
const_iterator before_begin() const noexcept;
|
|
|
|
const_iterator cbefore_begin() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-03 00:44:28 +08:00
|
|
|
bool empty() const noexcept;
|
|
|
|
size_type max_size() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
reference front();
|
|
|
|
const_reference front() const;
|
|
|
|
|
2017-01-25 07:09:12 +08:00
|
|
|
template <class... Args> reference emplace_front(Args&&... args); // reference in C++17
|
2010-05-12 03:42:16 +08:00
|
|
|
void push_front(const value_type& v);
|
|
|
|
void push_front(value_type&& v);
|
|
|
|
|
|
|
|
void pop_front();
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
iterator emplace_after(const_iterator p, Args&&... args);
|
|
|
|
iterator insert_after(const_iterator p, const value_type& v);
|
|
|
|
iterator insert_after(const_iterator p, value_type&& v);
|
|
|
|
iterator insert_after(const_iterator p, size_type n, const value_type& v);
|
|
|
|
template <class InputIterator>
|
|
|
|
iterator insert_after(const_iterator p,
|
|
|
|
InputIterator first, InputIterator last);
|
|
|
|
iterator insert_after(const_iterator p, initializer_list<value_type> il);
|
|
|
|
|
2010-08-22 04:58:44 +08:00
|
|
|
iterator erase_after(const_iterator p);
|
|
|
|
iterator erase_after(const_iterator first, const_iterator last);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
void swap(forward_list& x)
|
2015-07-14 04:04:56 +08:00
|
|
|
noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
void resize(size_type n);
|
|
|
|
void resize(size_type n, const value_type& v);
|
2011-06-03 00:44:28 +08:00
|
|
|
void clear() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-01-28 05:00:35 +08:00
|
|
|
void splice_after(const_iterator p, forward_list& x);
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator p, forward_list&& x);
|
2011-01-28 05:00:35 +08:00
|
|
|
void splice_after(const_iterator p, forward_list& x, const_iterator i);
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator p, forward_list&& x, const_iterator i);
|
2011-01-28 05:00:35 +08:00
|
|
|
void splice_after(const_iterator p, forward_list& x,
|
|
|
|
const_iterator first, const_iterator last);
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator p, forward_list&& x,
|
|
|
|
const_iterator first, const_iterator last);
|
2019-07-08 11:45:28 +08:00
|
|
|
size_type remove(const value_type& v); // void before C++20
|
|
|
|
template <class Predicate>
|
|
|
|
size_type remove_if(Predicate pred); // void before C++20
|
|
|
|
size_type unique(); // void before C++20
|
|
|
|
template <class BinaryPredicate>
|
|
|
|
size_type unique(BinaryPredicate binary_pred); // void before C++20
|
2011-01-28 05:00:35 +08:00
|
|
|
void merge(forward_list& x);
|
2010-05-12 03:42:16 +08:00
|
|
|
void merge(forward_list&& x);
|
2011-01-28 05:00:35 +08:00
|
|
|
template <class Compare> void merge(forward_list& x, Compare comp);
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class Compare> void merge(forward_list&& x, Compare comp);
|
|
|
|
void sort();
|
|
|
|
template <class Compare> void sort(Compare comp);
|
2011-06-03 00:44:28 +08:00
|
|
|
void reverse() noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2018-05-20 00:02:05 +08:00
|
|
|
|
|
|
|
template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
|
|
|
forward_list(InputIterator, InputIterator, Allocator = Allocator())
|
|
|
|
-> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator==(const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator< (const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator!=(const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator> (const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator>=(const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
|
|
|
bool operator<=(const forward_list<T, Allocator>& x,
|
|
|
|
const forward_list<T, Allocator>& y);
|
|
|
|
|
|
|
|
template <class T, class Allocator>
|
2011-06-04 00:20:53 +08:00
|
|
|
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
2011-06-04 01:30:28 +08:00
|
|
|
noexcept(noexcept(x.swap(y)));
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-12-15 02:49:35 +08:00
|
|
|
template <class T, class Allocator, class U>
|
2020-05-02 19:58:03 +08:00
|
|
|
typename forward_list<T, Allocator>::size_type
|
|
|
|
erase(forward_list<T, Allocator>& c, const U& value); // C++20
|
2018-12-15 02:49:35 +08:00
|
|
|
template <class T, class Allocator, class Predicate>
|
2020-05-02 19:58:03 +08:00
|
|
|
typename forward_list<T, Allocator>::size_type
|
|
|
|
erase_if(forward_list<T, Allocator>& c, Predicate pred); // C++20
|
2018-12-15 02:49:35 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-02-16 01:18:08 +08:00
|
|
|
#include <__algorithm/comp.h>
|
|
|
|
#include <__algorithm/lexicographical_compare.h>
|
|
|
|
#include <__algorithm/min.h>
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2010-05-12 03:42:16 +08:00
|
|
|
#include <__config>
|
2022-06-11 01:53:10 +08:00
|
|
|
#include <__iterator/distance.h>
|
|
|
|
#include <__iterator/iterator_traits.h>
|
|
|
|
#include <__iterator/move_iterator.h>
|
|
|
|
#include <__iterator/next.h>
|
2021-06-05 10:47:47 +08:00
|
|
|
#include <__utility/forward.h>
|
2021-05-19 23:57:04 +08:00
|
|
|
#include <limits>
|
|
|
|
#include <memory>
|
[libcxx][NFC] Make sequence containers slightly more SFINAE-friendly during CTAD.
Disable the constructors taking `(size_type, const value_type&,
allocator_type)` if `allocator_type` is not a valid allocator.
Otherwise, these constructors are considered when resolving e.g.
`(int*, int*, NotAnAllocator())`, leading to a hard error during
instantiation. A hard error makes the Standard's requirement to not
consider deduction guides of the form `(Iterator, Iterator,
BadAllocator)` during overload resolution essentially non-functional.
The previous approach was to SFINAE away `allocator_traits`. This patch
SFINAEs away the specific constructors instead, for consistency with
`basic_string` -- see [LWG3076](wg21.link/lwg3076) which describes
a very similar problem for strings (note, however, that unlike LWG3076,
no valid constructor call is affected by the bad instantiation).
Differential Revision: https://reviews.llvm.org/D114311
2021-12-02 03:55:46 +08:00
|
|
|
#include <type_traits>
|
2018-09-13 03:41:40 +08:00
|
|
|
#include <version>
|
2010-05-12 03:42:16 +08:00
|
|
|
|
[libc++] Re-add transitive includes that had been removed since LLVM 14
This commit re-adds transitive includes that had been removed by
4cd04d1687f1, c36870c8e79c, a83f4b9cda57, 1458458b558d, 2e2f3158c604,
and 489637e66dd3. This should cover almost all the includes that had
been removed since LLVM 14 and that would contribute to breaking user
code when releasing LLVM 15.
It is possible to disable the inclusion of these headers by defining
_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will
enable that macro and start fixing downstream issues immediately. We
can then remove the macro (and the transitive includes) by default in
a future release. That way, we will break users only once by removing
transitive includes in bulk instead of doing it bit by bit a every
release, which is more disruptive for users.
Note 1: The set of headers to re-add was found by re-generating the
transitive include test on a checkout of release/14.x, which
provided the list of all transitive includes we used to provide.
Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map>
have been added in this commit. These transitive inclusions were
added when we implemented boyer_moore_searcher in <functional>.
Note 3: This is a best effort patch to try and resolve downstream breakage
caused since branching LLVM 14. I wasn't able to perfectly mirror
transitive includes in LLVM 14 for a few headers, so I added a
release note explaining it. To summarize, adding boyer_moore_searcher
created a bunch of circular dependencies, so we have to break
backwards compatibility in a few cases.
Differential Revision: https://reviews.llvm.org/D128661
2022-06-28 03:53:41 +08:00
|
|
|
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
|
|
|
|
# include <algorithm>
|
|
|
|
# include <functional>
|
|
|
|
# include <iterator>
|
|
|
|
#endif
|
|
|
|
|
2022-06-17 04:43:46 +08:00
|
|
|
// standard-mandated includes
|
|
|
|
|
|
|
|
// [iterator.range]
|
|
|
|
#include <__iterator/access.h>
|
|
|
|
#include <__iterator/data.h>
|
|
|
|
#include <__iterator/empty.h>
|
|
|
|
#include <__iterator/reverse_access.h>
|
|
|
|
#include <__iterator/size.h>
|
|
|
|
|
|
|
|
// [forward.list.syn]
|
|
|
|
#include <compare>
|
|
|
|
#include <initializer_list>
|
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
2011-06-15 03:58:17 +08:00
|
|
|
template <class _Tp, class _VoidPtr> struct __forward_list_node;
|
2016-01-27 08:11:54 +08:00
|
|
|
template <class _NodePtr> struct __forward_begin_node;
|
|
|
|
|
|
|
|
|
|
|
|
template <class>
|
|
|
|
struct __forward_list_node_value_type;
|
|
|
|
|
|
|
|
template <class _Tp, class _VoidPtr>
|
|
|
|
struct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > {
|
|
|
|
typedef _Tp type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __forward_node_traits {
|
|
|
|
|
|
|
|
typedef typename remove_cv<
|
|
|
|
typename pointer_traits<_NodePtr>::element_type>::type __node;
|
|
|
|
typedef typename __forward_list_node_value_type<__node>::type __node_value_type;
|
|
|
|
typedef _NodePtr __node_pointer;
|
|
|
|
typedef __forward_begin_node<_NodePtr> __begin_node;
|
|
|
|
typedef typename __rebind_pointer<_NodePtr, __begin_node>::type
|
|
|
|
__begin_node_pointer;
|
|
|
|
typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
|
|
|
|
|
|
|
|
#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB)
|
|
|
|
typedef __begin_node_pointer __iter_node_pointer;
|
|
|
|
#else
|
|
|
|
typedef typename conditional<
|
|
|
|
is_pointer<__void_pointer>::value,
|
|
|
|
__begin_node_pointer,
|
|
|
|
__node_pointer
|
|
|
|
>::type __iter_node_pointer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef typename conditional<
|
|
|
|
is_same<__iter_node_pointer, __node_pointer>::value,
|
|
|
|
__begin_node_pointer,
|
|
|
|
__node_pointer
|
|
|
|
>::type __non_iter_node_pointer;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) {
|
|
|
|
return __p;
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) {
|
|
|
|
return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p));
|
|
|
|
}
|
|
|
|
};
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _NodePtr>
|
|
|
|
struct __forward_begin_node
|
|
|
|
{
|
|
|
|
typedef _NodePtr pointer;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename __rebind_pointer<_NodePtr, __forward_begin_node>::type __begin_node_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
pointer __next_;
|
|
|
|
|
2016-01-27 08:11:54 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__begin_node_pointer __next_as_begin() const {
|
|
|
|
return static_cast<__begin_node_pointer>(__next_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _VoidPtr>
|
2014-02-05 09:44:17 +08:00
|
|
|
struct _LIBCPP_HIDDEN __begin_node_of
|
|
|
|
{
|
2015-12-31 05:52:00 +08:00
|
|
|
typedef __forward_begin_node<
|
|
|
|
typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type
|
|
|
|
> type;
|
2014-02-05 09:44:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _VoidPtr>
|
2021-03-16 05:20:49 +08:00
|
|
|
struct _LIBCPP_STANDALONE_DEBUG __forward_list_node
|
2014-02-05 09:44:17 +08:00
|
|
|
: public __begin_node_of<_Tp, _VoidPtr>::type
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
typedef _Tp value_type;
|
|
|
|
|
|
|
|
value_type __value_;
|
|
|
|
};
|
|
|
|
|
2016-01-27 08:11:54 +08:00
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list;
|
|
|
|
template<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _NodePtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __forward_list_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef __forward_node_traits<_NodePtr> __traits;
|
|
|
|
typedef typename __traits::__node_pointer __node_pointer;
|
|
|
|
typedef typename __traits::__begin_node_pointer __begin_node_pointer;
|
|
|
|
typedef typename __traits::__iter_node_pointer __iter_node_pointer;
|
|
|
|
typedef typename __traits::__void_pointer __void_pointer;
|
|
|
|
|
|
|
|
__iter_node_pointer __ptr_;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__begin_node_pointer __get_begin() const {
|
|
|
|
return static_cast<__begin_node_pointer>(
|
|
|
|
static_cast<__void_pointer>(__ptr_));
|
|
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
__node_pointer __get_unsafe_node_pointer() const {
|
|
|
|
return static_cast<__node_pointer>(
|
|
|
|
static_cast<__void_pointer>(__ptr_));
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-01-27 08:11:54 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
|
|
|
|
: __ptr_(__traits::__as_iter_node(__p)) {}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
|
|
|
|
: __ptr_(__traits::__as_iter_node(__p)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-05 07:56:00 +08:00
|
|
|
template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list;
|
|
|
|
template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef forward_iterator_tag iterator_category;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename __traits::__node_value_type value_type;
|
2013-06-25 01:17:28 +08:00
|
|
|
typedef value_type& reference;
|
2010-08-22 08:02:43 +08:00
|
|
|
typedef typename pointer_traits<__node_pointer>::difference_type
|
2010-05-12 03:42:16 +08:00
|
|
|
difference_type;
|
2015-12-31 05:52:00 +08:00
|
|
|
typedef typename __rebind_pointer<__node_pointer, value_type>::type pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
__forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
pointer operator->() const {
|
|
|
|
return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_iterator& operator++()
|
|
|
|
{
|
2016-01-27 08:49:20 +08:00
|
|
|
__ptr_ = __traits::__as_iter_node(__ptr_->__next_);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__forward_list_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __forward_list_iterator& __x,
|
|
|
|
const __forward_list_iterator& __y)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.__ptr_ == __y.__ptr_;}
|
2010-09-22 06:55:27 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __forward_list_iterator& __x,
|
|
|
|
const __forward_list_iterator& __y)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return !(__x == __y);}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _NodeConstPtr>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), "");
|
|
|
|
typedef _NodeConstPtr _NodePtr;
|
|
|
|
|
|
|
|
typedef __forward_node_traits<_NodePtr> __traits;
|
|
|
|
typedef typename __traits::__node __node;
|
|
|
|
typedef typename __traits::__node_pointer __node_pointer;
|
|
|
|
typedef typename __traits::__begin_node_pointer __begin_node_pointer;
|
|
|
|
typedef typename __traits::__iter_node_pointer __iter_node_pointer;
|
|
|
|
typedef typename __traits::__void_pointer __void_pointer;
|
|
|
|
|
|
|
|
__iter_node_pointer __ptr_;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __get_begin() const {
|
|
|
|
return static_cast<__begin_node_pointer>(
|
|
|
|
static_cast<__void_pointer>(__ptr_));
|
|
|
|
}
|
|
|
|
__node_pointer __get_unsafe_node_pointer() const {
|
|
|
|
return static_cast<__node_pointer>(
|
|
|
|
static_cast<__void_pointer>(__ptr_));
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
|
|
|
|
: __ptr_(nullptr) {}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
|
|
|
|
: __ptr_(__traits::__as_iter_node(__p)) {}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
|
|
|
|
: __ptr_(__traits::__as_iter_node(__p)) {}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<class, class> friend class forward_list;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef forward_iterator_tag iterator_category;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename __traits::__node_value_type value_type;
|
2013-06-25 01:17:28 +08:00
|
|
|
typedef const value_type& reference;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename pointer_traits<__node_pointer>::difference_type
|
2010-05-12 03:42:16 +08:00
|
|
|
difference_type;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename __rebind_pointer<__node_pointer, const value_type>::type
|
|
|
|
pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
__forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
__forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
: __ptr_(__p.__ptr_) {}
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
pointer operator->() const {return pointer_traits<pointer>::pointer_to(
|
|
|
|
__get_unsafe_node_pointer()->__value_);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_const_iterator& operator++()
|
|
|
|
{
|
2016-01-27 08:49:20 +08:00
|
|
|
__ptr_ = __traits::__as_iter_node(__ptr_->__next_);
|
2010-05-12 03:42:16 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_const_iterator operator++(int)
|
|
|
|
{
|
|
|
|
__forward_list_const_iterator __t(*this);
|
|
|
|
++(*this);
|
|
|
|
return __t;
|
|
|
|
}
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const __forward_list_const_iterator& __x,
|
|
|
|
const __forward_list_const_iterator& __y)
|
2010-05-12 03:42:16 +08:00
|
|
|
{return __x.__ptr_ == __y.__ptr_;}
|
2010-09-22 06:55:27 +08:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const __forward_list_const_iterator& __x,
|
2010-05-12 03:42:16 +08:00
|
|
|
const __forward_list_const_iterator& __y)
|
|
|
|
{return !(__x == __y);}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
class __forward_list_base
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef _Alloc allocator_type;
|
|
|
|
|
2014-02-05 09:44:17 +08:00
|
|
|
typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
|
|
|
|
typedef __forward_list_node<value_type, void_pointer> __node;
|
|
|
|
typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
|
2015-04-07 13:21:38 +08:00
|
|
|
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
|
2010-05-12 03:42:16 +08:00
|
|
|
typedef allocator_traits<__node_allocator> __node_traits;
|
|
|
|
typedef typename __node_traits::pointer __node_pointer;
|
2013-06-25 01:17:28 +08:00
|
|
|
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename __rebind_alloc_helper<
|
|
|
|
allocator_traits<allocator_type>, __begin_node
|
|
|
|
>::type __begin_node_allocator;
|
|
|
|
typedef typename allocator_traits<__begin_node_allocator>::pointer
|
|
|
|
__begin_node_pointer;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2018-06-06 06:32:52 +08:00
|
|
|
static_assert((!is_same<allocator_type, __node_allocator>::value),
|
|
|
|
"internal allocator type must differ from user-specified "
|
|
|
|
"type; otherwise overload resolution breaks");
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
__compressed_pair<__begin_node, __node_allocator> __before_begin_;
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __before_begin() _NOEXCEPT
|
|
|
|
{return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __before_begin() const _NOEXCEPT
|
|
|
|
{return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
__node_allocator& __alloc() _NOEXCEPT
|
|
|
|
{return __before_begin_.second();}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const __node_allocator& __alloc() const _NOEXCEPT
|
|
|
|
{return __before_begin_.second();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
typedef __forward_list_iterator<__node_pointer> iterator;
|
2013-06-25 01:17:28 +08:00
|
|
|
typedef __forward_list_const_iterator<__node_pointer> const_iterator;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_base()
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
|
2019-12-17 07:23:39 +08:00
|
|
|
: __before_begin_(__begin_node(), __default_init_tag()) {}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-06-06 06:32:52 +08:00
|
|
|
explicit __forward_list_base(const allocator_type& __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
: __before_begin_(__begin_node(), __node_allocator(__a)) {}
|
2018-06-06 06:32:52 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
explicit __forward_list_base(const __node_allocator& __a)
|
|
|
|
: __before_begin_(__begin_node(), __a) {}
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-04 00:20:53 +08:00
|
|
|
public:
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
__forward_list_base(__forward_list_base&& __x)
|
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
__forward_list_base(const __forward_list_base&);
|
|
|
|
__forward_list_base& operator=(const __forward_list_base&);
|
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
public:
|
2010-05-12 03:42:16 +08:00
|
|
|
~__forward_list_base();
|
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
protected:
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __copy_assign_alloc(const __forward_list_base& __x)
|
|
|
|
{__copy_assign_alloc(__x, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_copy_assignment::value>());}
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __move_assign_alloc(__forward_list_base& __x)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
|
|
|
|
is_nothrow_move_assignable<__node_allocator>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{__move_assign_alloc(__x, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value>());}
|
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
public:
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
void swap(__forward_list_base& __x)
|
2015-07-14 04:04:56 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_NOEXCEPT;
|
|
|
|
#else
|
2021-06-23 00:37:51 +08:00
|
|
|
_NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
|
2015-07-14 04:04:56 +08:00
|
|
|
__is_nothrow_swappable<__node_allocator>::value);
|
|
|
|
#endif
|
2011-06-04 00:20:53 +08:00
|
|
|
protected:
|
2011-06-03 00:44:28 +08:00
|
|
|
void clear() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __copy_assign_alloc(const __forward_list_base&, false_type) {}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __copy_assign_alloc(const __forward_list_base& __x, true_type)
|
|
|
|
{
|
|
|
|
if (__alloc() != __x.__alloc())
|
|
|
|
clear();
|
|
|
|
__alloc() = __x.__alloc();
|
|
|
|
}
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-12-24 07:37:52 +08:00
|
|
|
void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT
|
2011-06-04 00:20:53 +08:00
|
|
|
{}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void __move_assign_alloc(__forward_list_base& __x, true_type)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
{__alloc() = _VSTD::move(__x.__alloc());}
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
: __before_begin_(_VSTD::move(__x.__before_begin_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.__before_begin()->__next_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
|
|
|
|
const allocator_type& __a)
|
|
|
|
: __before_begin_(__begin_node(), __node_allocator(__a))
|
|
|
|
{
|
|
|
|
if (__alloc() == __x.__alloc())
|
|
|
|
{
|
|
|
|
__before_begin()->__next_ = __x.__before_begin()->__next_;
|
|
|
|
__x.__before_begin()->__next_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
|
2015-07-14 04:04:56 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_NOEXCEPT
|
|
|
|
#else
|
2021-06-23 00:37:51 +08:00
|
|
|
_NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
|
2015-07-14 04:04:56 +08:00
|
|
|
__is_nothrow_swappable<__node_allocator>::value)
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2020-11-19 07:54:38 +08:00
|
|
|
_VSTD::__swap_allocator(__alloc(), __x.__alloc(),
|
2015-07-14 04:04:56 +08:00
|
|
|
integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
|
2011-07-01 05:18:19 +08:00
|
|
|
using _VSTD::swap;
|
2010-05-12 03:42:16 +08:00
|
|
|
swap(__before_begin()->__next_, __x.__before_begin()->__next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
2011-06-03 00:44:28 +08:00
|
|
|
__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_allocator& __a = __alloc();
|
|
|
|
for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
|
|
|
|
{
|
|
|
|
__node_pointer __next = __p->__next_;
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __p, 1);
|
|
|
|
__p = __next;
|
|
|
|
}
|
|
|
|
__before_begin()->__next_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-19 01:24:08 +08:00
|
|
|
template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
|
2017-01-05 07:56:00 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS forward_list
|
2010-05-12 03:42:16 +08:00
|
|
|
: private __forward_list_base<_Tp, _Alloc>
|
|
|
|
{
|
|
|
|
typedef __forward_list_base<_Tp, _Alloc> base;
|
2011-06-04 00:20:53 +08:00
|
|
|
typedef typename base::__node_allocator __node_allocator;
|
2016-01-27 08:11:54 +08:00
|
|
|
typedef typename base::__node __node;
|
|
|
|
typedef typename base::__node_traits __node_traits;
|
|
|
|
typedef typename base::__node_pointer __node_pointer;
|
|
|
|
typedef typename base::__begin_node_pointer __begin_node_pointer;
|
2011-06-04 00:20:53 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
public:
|
|
|
|
typedef _Tp value_type;
|
|
|
|
typedef _Alloc allocator_type;
|
|
|
|
|
2015-11-26 09:24:04 +08:00
|
|
|
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
|
|
|
|
"Allocator::value_type must be same type as value_type");
|
|
|
|
|
[libcxx][NFC] Make sequence containers slightly more SFINAE-friendly during CTAD.
Disable the constructors taking `(size_type, const value_type&,
allocator_type)` if `allocator_type` is not a valid allocator.
Otherwise, these constructors are considered when resolving e.g.
`(int*, int*, NotAnAllocator())`, leading to a hard error during
instantiation. A hard error makes the Standard's requirement to not
consider deduction guides of the form `(Iterator, Iterator,
BadAllocator)` during overload resolution essentially non-functional.
The previous approach was to SFINAE away `allocator_traits`. This patch
SFINAEs away the specific constructors instead, for consistency with
`basic_string` -- see [LWG3076](wg21.link/lwg3076) which describes
a very similar problem for strings (note, however, that unlike LWG3076,
no valid constructor call is affected by the bad instantiation).
Differential Revision: https://reviews.llvm.org/D114311
2021-12-02 03:55:46 +08:00
|
|
|
typedef value_type& reference;
|
|
|
|
typedef const value_type& const_reference;
|
|
|
|
typedef typename allocator_traits<allocator_type>::pointer pointer;
|
|
|
|
typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
|
|
|
|
typedef typename allocator_traits<allocator_type>::size_type size_type;
|
|
|
|
typedef typename allocator_traits<allocator_type>::difference_type difference_type;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
typedef typename base::iterator iterator;
|
|
|
|
typedef typename base::const_iterator const_iterator;
|
2019-07-08 11:45:28 +08:00
|
|
|
#if _LIBCPP_STD_VER > 17
|
|
|
|
typedef size_type __remove_return_type;
|
|
|
|
#else
|
|
|
|
typedef void __remove_return_type;
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-06-04 00:20:53 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
forward_list()
|
|
|
|
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
|
|
|
|
{} // = default;
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
explicit forward_list(const allocator_type& __a);
|
|
|
|
explicit forward_list(size_type __n);
|
2013-09-09 03:11:51 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
explicit forward_list(size_type __n, const allocator_type& __a);
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list(size_type __n, const value_type& __v);
|
[libcxx][NFC] Make sequence containers slightly more SFINAE-friendly during CTAD.
Disable the constructors taking `(size_type, const value_type&,
allocator_type)` if `allocator_type` is not a valid allocator.
Otherwise, these constructors are considered when resolving e.g.
`(int*, int*, NotAnAllocator())`, leading to a hard error during
instantiation. A hard error makes the Standard's requirement to not
consider deduction guides of the form `(Iterator, Iterator,
BadAllocator)` during overload resolution essentially non-functional.
The previous approach was to SFINAE away `allocator_traits`. This patch
SFINAEs away the specific constructors instead, for consistency with
`basic_string` -- see [LWG3076](wg21.link/lwg3076) which describes
a very similar problem for strings (note, however, that unlike LWG3076,
no valid constructor call is affected by the bad instantiation).
Differential Revision: https://reviews.llvm.org/D114311
2021-12-02 03:55:46 +08:00
|
|
|
|
|
|
|
template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
|
|
|
|
forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __n, __v);
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _InputIterator>
|
|
|
|
forward_list(_InputIterator __f, _InputIterator __l,
|
|
|
|
typename enable_if<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value
|
2010-05-12 03:42:16 +08:00
|
|
|
>::type* = nullptr);
|
|
|
|
template <class _InputIterator>
|
|
|
|
forward_list(_InputIterator __f, _InputIterator __l,
|
|
|
|
const allocator_type& __a,
|
|
|
|
typename enable_if<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value
|
2010-05-12 03:42:16 +08:00
|
|
|
>::type* = nullptr);
|
|
|
|
forward_list(const forward_list& __x);
|
2022-03-19 00:49:02 +08:00
|
|
|
forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
|
2017-04-16 12:02:01 +08:00
|
|
|
|
|
|
|
forward_list& operator=(const forward_list& __x);
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
forward_list(forward_list&& __x)
|
|
|
|
_NOEXCEPT_(is_nothrow_move_constructible<base>::value)
|
2011-07-01 05:18:19 +08:00
|
|
|
: base(_VSTD::move(__x)) {}
|
2022-03-19 00:49:02 +08:00
|
|
|
forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
|
2017-04-16 12:02:01 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list(initializer_list<value_type> __il);
|
|
|
|
forward_list(initializer_list<value_type> __il, const allocator_type& __a);
|
|
|
|
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
forward_list& operator=(forward_list&& __x)
|
|
|
|
_NOEXCEPT_(
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<allocator_type>::value);
|
2017-04-16 12:02:01 +08:00
|
|
|
|
2016-04-22 09:04:55 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list& operator=(initializer_list<value_type> __il);
|
2017-04-16 12:02:01 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void assign(initializer_list<value_type> __il);
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2017-04-16 12:02:01 +08:00
|
|
|
|
|
|
|
// ~forward_list() = default;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _InputIterator>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
assign(_InputIterator __f, _InputIterator __l);
|
|
|
|
void assign(size_type __n, const value_type& __v);
|
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
allocator_type get_allocator() const _NOEXCEPT
|
|
|
|
{return allocator_type(base::__alloc());}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
iterator begin() _NOEXCEPT
|
|
|
|
{return iterator(base::__before_begin()->__next_);}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator begin() const _NOEXCEPT
|
|
|
|
{return const_iterator(base::__before_begin()->__next_);}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
iterator end() _NOEXCEPT
|
|
|
|
{return iterator(nullptr);}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator end() const _NOEXCEPT
|
|
|
|
{return const_iterator(nullptr);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator cbegin() const _NOEXCEPT
|
|
|
|
{return const_iterator(base::__before_begin()->__next_);}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator cend() const _NOEXCEPT
|
|
|
|
{return const_iterator(nullptr);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
iterator before_begin() _NOEXCEPT
|
|
|
|
{return iterator(base::__before_begin());}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator before_begin() const _NOEXCEPT
|
|
|
|
{return const_iterator(base::__before_begin());}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
const_iterator cbefore_begin() const _NOEXCEPT
|
|
|
|
{return const_iterator(base::__before_begin());}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-11-15 13:51:26 +08:00
|
|
|
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
bool empty() const _NOEXCEPT
|
|
|
|
{return base::__before_begin()->__next_ == nullptr;}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2016-11-23 09:18:56 +08:00
|
|
|
size_type max_size() const _NOEXCEPT {
|
[libc++] Consistently replace `std::` qualification with `_VSTD::` or nothing. NFCI.
I used a lot of `git grep` to find places where `std::` was being used
outside of comments and assert-messages. There were three outcomes:
- Qualified function calls, e.g. `std::move` becomes `_VSTD::move`.
This is the most common case.
- Typenames that don't need qualification, e.g. `std::allocator` becomes `allocator`.
Leaving these as `_VSTD::allocator` would also be fine, but I decided
that removing the qualification is more consistent with existing practice.
- Names that specifically need un-versioned `std::` qualification,
or that I wasn't sure about. For example, I didn't touch any code in
<atomic>, <math.h>, <new>, or any ext/ or experimental/ headers;
and I didn't touch any instances of `std::type_info`.
In some deduction guides, we were accidentally using `class Alloc = typename std::allocator<T>`,
despite `std::allocator<T>`'s type-ness not being template-dependent.
Because `std::allocator` is a qualified name, this did parse as we intended;
but what we meant was simply `class Alloc = allocator<T>`.
Differential Revision: https://reviews.llvm.org/D92250
2020-11-28 00:02:06 +08:00
|
|
|
return _VSTD::min<size_type>(
|
2016-11-23 09:18:56 +08:00
|
|
|
__node_traits::max_size(base::__alloc()),
|
|
|
|
numeric_limits<difference_type>::max());
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
reference front() {return base::__before_begin()->__next_->__value_;}
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
const_reference front() const {return base::__before_begin()->__next_->__value_;}
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2017-01-25 07:09:12 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
2016-07-21 11:20:17 +08:00
|
|
|
template <class... _Args> reference emplace_front(_Args&&... __args);
|
2017-01-25 07:09:12 +08:00
|
|
|
#else
|
|
|
|
template <class... _Args> void emplace_front(_Args&&... __args);
|
2010-09-05 07:28:19 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
void push_front(value_type&& __v);
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
void push_front(const value_type& __v);
|
|
|
|
|
|
|
|
void pop_front();
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class... _Args>
|
|
|
|
iterator emplace_after(const_iterator __p, _Args&&... __args);
|
2017-04-16 12:02:01 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator insert_after(const_iterator __p, value_type&& __v);
|
2017-04-16 12:02:01 +08:00
|
|
|
iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
|
|
|
|
{return insert_after(__p, __il.begin(), __il.end());}
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator insert_after(const_iterator __p, const value_type& __v);
|
|
|
|
iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
|
|
|
|
template <class _InputIterator>
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator
|
|
|
|
>::type
|
|
|
|
insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
|
|
|
|
|
2010-08-22 04:58:44 +08:00
|
|
|
iterator erase_after(const_iterator __p);
|
|
|
|
iterator erase_after(const_iterator __f, const_iterator __l);
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-04 00:20:53 +08:00
|
|
|
void swap(forward_list& __x)
|
2015-07-14 04:04:56 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 14
|
|
|
|
_NOEXCEPT
|
|
|
|
#else
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
|
|
|
|
__is_nothrow_swappable<__node_allocator>::value)
|
2015-07-14 04:04:56 +08:00
|
|
|
#endif
|
2011-06-04 00:20:53 +08:00
|
|
|
{base::swap(__x);}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
void resize(size_type __n);
|
|
|
|
void resize(size_type __n, const value_type& __v);
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-06-03 00:44:28 +08:00
|
|
|
void clear() _NOEXCEPT {base::clear();}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-01-28 05:00:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator __p, forward_list&& __x);
|
2011-01-28 05:00:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
|
2011-01-28 05:00:35 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void splice_after(const_iterator __p, forward_list&& __x,
|
|
|
|
const_iterator __f, const_iterator __l);
|
|
|
|
void splice_after(const_iterator __p, forward_list& __x);
|
|
|
|
void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
|
|
|
|
void splice_after(const_iterator __p, forward_list& __x,
|
|
|
|
const_iterator __f, const_iterator __l);
|
2019-07-08 11:45:28 +08:00
|
|
|
__remove_return_type remove(const value_type& __v);
|
|
|
|
template <class _Predicate> __remove_return_type remove_if(_Predicate __pred);
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-07-08 11:45:28 +08:00
|
|
|
__remove_return_type unique() {return unique(__equal_to<value_type>());}
|
|
|
|
template <class _BinaryPredicate> __remove_return_type unique(_BinaryPredicate __binary_pred);
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-01-28 05:00:35 +08:00
|
|
|
void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
|
|
|
|
template <class _Compare>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
void merge(forward_list&& __x, _Compare __comp)
|
2011-07-01 05:18:19 +08:00
|
|
|
{merge(__x, _VSTD::move(__comp));}
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void merge(forward_list& __x) {merge(__x, __less<value_type>());}
|
|
|
|
template <class _Compare> void merge(forward_list& __x, _Compare __comp);
|
2010-09-22 06:55:27 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void sort() {sort(__less<value_type>());}
|
2016-04-22 09:04:55 +08:00
|
|
|
template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp);
|
2011-06-03 00:44:28 +08:00
|
|
|
void reverse() _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-06-04 00:20:53 +08:00
|
|
|
void __move_assign(forward_list& __x, true_type)
|
|
|
|
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
|
2010-05-12 03:42:16 +08:00
|
|
|
void __move_assign(forward_list& __x, false_type);
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Compare>
|
|
|
|
static
|
|
|
|
__node_pointer
|
|
|
|
__merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
|
|
|
|
|
|
|
|
template <class _Compare>
|
|
|
|
static
|
|
|
|
__node_pointer
|
|
|
|
__sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
|
|
|
|
};
|
|
|
|
|
2018-05-20 00:02:05 +08:00
|
|
|
|
2021-08-17 23:59:07 +08:00
|
|
|
#if _LIBCPP_STD_VER >= 17
|
2018-05-20 00:02:05 +08:00
|
|
|
template<class _InputIterator,
|
2021-03-04 12:02:20 +08:00
|
|
|
class _Alloc = allocator<__iter_value_type<_InputIterator>>,
|
2021-11-10 01:21:02 +08:00
|
|
|
class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-18 00:26:09 +08:00
|
|
|
class = enable_if_t<__is_allocator<_Alloc>::value>
|
2018-05-20 00:02:05 +08:00
|
|
|
>
|
|
|
|
forward_list(_InputIterator, _InputIterator)
|
2021-03-04 12:02:20 +08:00
|
|
|
-> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
|
2018-05-20 00:02:05 +08:00
|
|
|
|
|
|
|
template<class _InputIterator,
|
|
|
|
class _Alloc,
|
2021-11-10 01:21:02 +08:00
|
|
|
class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
|
[libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:
candidate template ignored: substitution failure [with _Args =
<ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'
Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:
candidate template ignored: requirement 'is_invocable_v<
std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
ContiguousView>' was not satisfied [with _Args = <ContiguousView>]
Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.
Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.
I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).
Differential Revision: https://reviews.llvm.org/D108216
2021-08-18 00:26:09 +08:00
|
|
|
class = enable_if_t<__is_allocator<_Alloc>::value>
|
2018-05-20 00:02:05 +08:00
|
|
|
>
|
|
|
|
forward_list(_InputIterator, _InputIterator, _Alloc)
|
2021-03-04 12:02:20 +08:00
|
|
|
-> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
|
2018-05-20 00:02:05 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
|
|
|
|
: base(__a)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(size_type __n)
|
|
|
|
{
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
|
2016-01-27 08:11:54 +08:00
|
|
|
for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
|
|
|
|
__p = __p->__next_as_begin())
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = nullptr;
|
|
|
|
__p->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-09 03:11:51 +08:00
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-12-03 09:21:40 +08:00
|
|
|
forward_list<_Tp, _Alloc>::forward_list(size_type __n,
|
|
|
|
const allocator_type& __base_alloc)
|
|
|
|
: base ( __base_alloc )
|
2013-09-09 03:11:51 +08:00
|
|
|
{
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
|
2016-01-27 08:11:54 +08:00
|
|
|
for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
|
|
|
|
__p = __p->__next_as_begin())
|
2013-09-09 03:11:51 +08:00
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
|
|
|
|
__h->__next_ = nullptr;
|
|
|
|
__p->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __n, __v);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
|
|
|
|
typename enable_if<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value
|
2010-05-12 03:42:16 +08:00
|
|
|
>::type*)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __f, __l);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
|
|
|
|
const allocator_type& __a,
|
|
|
|
typename enable_if<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value
|
2010-05-12 03:42:16 +08:00
|
|
|
>::type*)
|
|
|
|
: base(__a)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __f, __l);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
|
2018-06-06 06:32:52 +08:00
|
|
|
: base(
|
|
|
|
__node_traits::select_on_container_copy_construction(__x.__alloc())) {
|
|
|
|
insert_after(cbefore_begin(), __x.begin(), __x.end());
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
|
2022-03-19 00:49:02 +08:00
|
|
|
const __type_identity_t<allocator_type>& __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
: base(__a)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __x.begin(), __x.end());
|
|
|
|
}
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>&
|
|
|
|
forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
|
|
|
|
{
|
2021-09-29 01:15:18 +08:00
|
|
|
if (this != _VSTD::addressof(__x))
|
2017-04-16 12:02:01 +08:00
|
|
|
{
|
|
|
|
base::__copy_assign_alloc(__x);
|
|
|
|
assign(__x.begin(), __x.end());
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
|
2022-03-19 00:49:02 +08:00
|
|
|
const __type_identity_t<allocator_type>& __a)
|
2011-07-01 05:18:19 +08:00
|
|
|
: base(_VSTD::move(__x), __a)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
if (base::__alloc() != __x.__alloc())
|
|
|
|
{
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef move_iterator<iterator> _Ip;
|
|
|
|
insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __il.begin(), __il.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
|
|
|
|
const allocator_type& __a)
|
|
|
|
: base(__a)
|
|
|
|
{
|
|
|
|
insert_after(cbefore_begin(), __il.begin(), __il.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
base::__move_assign_alloc(__x);
|
|
|
|
base::__before_begin()->__next_ = __x.__before_begin()->__next_;
|
|
|
|
__x.__before_begin()->__next_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
|
|
|
|
{
|
|
|
|
if (base::__alloc() == __x.__alloc())
|
|
|
|
__move_assign(__x, true_type());
|
|
|
|
else
|
|
|
|
{
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef move_iterator<iterator> _Ip;
|
|
|
|
assign(_Ip(__x.begin()), _Ip(__x.end()));
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>&
|
|
|
|
forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value &&
|
|
|
|
is_nothrow_move_assignable<allocator_type>::value)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__move_assign(__x, integral_constant<bool,
|
|
|
|
__node_traits::propagate_on_container_move_assignment::value>());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>&
|
|
|
|
forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
|
|
|
|
{
|
|
|
|
assign(__il.begin(), __il.end());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2011-08-13 05:56:02 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
>::type
|
|
|
|
forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
|
|
|
|
{
|
|
|
|
iterator __i = before_begin();
|
2011-07-01 05:18:19 +08:00
|
|
|
iterator __j = _VSTD::next(__i);
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __e = end();
|
2014-10-28 03:28:20 +08:00
|
|
|
for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
|
2010-05-12 03:42:16 +08:00
|
|
|
*__j = *__f;
|
|
|
|
if (__j == __e)
|
|
|
|
insert_after(__i, __f, __l);
|
|
|
|
else
|
|
|
|
erase_after(__i, __e);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
|
|
|
|
{
|
|
|
|
iterator __i = before_begin();
|
2011-07-01 05:18:19 +08:00
|
|
|
iterator __j = _VSTD::next(__i);
|
2010-05-12 03:42:16 +08:00
|
|
|
iterator __e = end();
|
|
|
|
for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
|
|
|
|
*__j = __v;
|
|
|
|
if (__j == __e)
|
|
|
|
insert_after(__i, __n, __v);
|
|
|
|
else
|
|
|
|
erase_after(__i, __e);
|
|
|
|
}
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2011-08-13 05:56:02 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
|
|
|
|
{
|
|
|
|
assign(__il.begin(), __il.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class... _Args>
|
2017-01-25 07:09:12 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
2016-07-21 11:20:17 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::reference
|
2017-01-25 07:09:12 +08:00
|
|
|
#else
|
|
|
|
void
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_),
|
|
|
|
_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = base::__before_begin()->__next_;
|
|
|
|
base::__before_begin()->__next_ = __h.release();
|
2017-01-25 07:09:12 +08:00
|
|
|
#if _LIBCPP_STD_VER > 14
|
2016-07-21 11:20:17 +08:00
|
|
|
return base::__before_begin()->__next_->__value_;
|
2017-01-25 07:09:12 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = base::__before_begin()->__next_;
|
|
|
|
base::__before_begin()->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = base::__before_begin()->__next_;
|
|
|
|
base::__before_begin()->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::pop_front()
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
|
|
|
__node_pointer __p = base::__before_begin()->__next_;
|
|
|
|
base::__before_begin()->__next_ = __p->__next_;
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __p, 1);
|
|
|
|
}
|
|
|
|
|
2017-04-16 12:02:01 +08:00
|
|
|
#ifndef _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class... _Args>
|
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
|
|
|
forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer const __r = __p.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_),
|
|
|
|
_VSTD::forward<_Args>(__args)...);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = __r->__next_;
|
|
|
|
__r->__next_ = __h.release();
|
|
|
|
return iterator(__r->__next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
|
|
|
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer const __r = __p.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = __r->__next_;
|
|
|
|
__r->__next_ = __h.release();
|
|
|
|
return iterator(__r->__next_);
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_CXX03_LANG
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
|
|
|
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer const __r = __p.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = __r->__next_;
|
|
|
|
__r->__next_ = __h.release();
|
|
|
|
return iterator(__r->__next_);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
|
|
|
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
|
|
|
|
const value_type& __v)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __r = __p.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_pointer __first = __h.release();
|
|
|
|
__node_pointer __last = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
for (--__n; __n != 0; --__n, __last = __last->__next_)
|
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__last->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
while (__first != nullptr)
|
|
|
|
{
|
|
|
|
__node_pointer __next = __first->__next_;
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __first, 1);
|
|
|
|
__first = __next;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
__last->__next_ = __r->__next_;
|
|
|
|
__r->__next_ = __first;
|
2016-01-27 08:11:54 +08:00
|
|
|
__r = static_cast<__begin_node_pointer>(__last);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
return iterator(__r);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _InputIterator>
|
|
|
|
typename enable_if
|
|
|
|
<
|
2019-11-18 14:46:58 +08:00
|
|
|
__is_cpp17_input_iterator<_InputIterator>::value,
|
2010-05-12 03:42:16 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
|
|
|
>::type
|
|
|
|
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
|
|
|
|
_InputIterator __f, _InputIterator __l)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __r = __p.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__f != __l)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_pointer __first = __h.release();
|
|
|
|
__node_pointer __last = __first;
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
try
|
|
|
|
{
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2014-10-28 03:28:20 +08:00
|
|
|
for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
|
2010-05-12 03:42:16 +08:00
|
|
|
__last->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
while (__first != nullptr)
|
|
|
|
{
|
|
|
|
__node_pointer __next = __first->__next_;
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __first, 1);
|
|
|
|
__first = __next;
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-12 03:42:16 +08:00
|
|
|
__last->__next_ = __r->__next_;
|
|
|
|
__r->__next_ = __first;
|
2016-01-27 08:11:54 +08:00
|
|
|
__r = static_cast<__begin_node_pointer>(__last);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
return iterator(__r);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-08-22 04:58:44 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __p = __f.__get_begin();
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_pointer __n = __p->__next_;
|
|
|
|
__p->__next_ = __n->__next_;
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __n, 1);
|
2010-08-22 04:58:44 +08:00
|
|
|
return iterator(__p->__next_);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-08-22 04:58:44 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::iterator
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__node_pointer __e = __l.__get_unsafe_node_pointer();
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__f != __l)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__begin_node_pointer __bp = __f.__get_begin();
|
|
|
|
|
|
|
|
__node_pointer __n = __bp->__next_;
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__n != __e)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__bp->__next_ = __e;
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_allocator& __a = base::__alloc();
|
|
|
|
do
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__node_pointer __tmp = __n->__next_;
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_traits::deallocate(__a, __n, 1);
|
2016-01-27 08:11:54 +08:00
|
|
|
__n = __tmp;
|
2010-05-12 03:42:16 +08:00
|
|
|
} while (__n != __e);
|
|
|
|
}
|
|
|
|
}
|
2010-08-22 04:58:44 +08:00
|
|
|
return iterator(__e);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::resize(size_type __n)
|
|
|
|
{
|
|
|
|
size_type __sz = 0;
|
|
|
|
iterator __p = before_begin();
|
|
|
|
iterator __i = begin();
|
|
|
|
iterator __e = end();
|
|
|
|
for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
|
|
|
|
;
|
|
|
|
if (__i != __e)
|
|
|
|
erase_after(__p, __e);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__n -= __sz;
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
|
2016-01-27 08:11:54 +08:00
|
|
|
for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
|
|
|
|
__ptr = __ptr->__next_as_begin())
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = nullptr;
|
|
|
|
__ptr->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
|
|
|
|
{
|
|
|
|
size_type __sz = 0;
|
|
|
|
iterator __p = before_begin();
|
|
|
|
iterator __i = begin();
|
|
|
|
iterator __e = end();
|
|
|
|
for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
|
|
|
|
;
|
|
|
|
if (__i != __e)
|
|
|
|
erase_after(__p, __e);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__n -= __sz;
|
|
|
|
if (__n > 0)
|
|
|
|
{
|
|
|
|
__node_allocator& __a = base::__alloc();
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef __allocator_destructor<__node_allocator> _Dp;
|
|
|
|
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
|
2016-01-27 08:11:54 +08:00
|
|
|
for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
|
|
|
|
__ptr = __ptr->__next_as_begin())
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__h.reset(__node_traits::allocate(__a, 1));
|
2011-07-01 05:18:19 +08:00
|
|
|
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
|
2010-05-12 03:42:16 +08:00
|
|
|
__h->__next_ = nullptr;
|
|
|
|
__ptr->__next_ = __h.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
|
|
|
forward_list& __x)
|
|
|
|
{
|
|
|
|
if (!__x.empty())
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
if (__p.__get_begin()->__next_ != nullptr)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
const_iterator __lm1 = __x.before_begin();
|
2016-01-27 08:11:54 +08:00
|
|
|
while (__lm1.__get_begin()->__next_ != nullptr)
|
2010-05-12 03:42:16 +08:00
|
|
|
++__lm1;
|
2016-01-27 08:11:54 +08:00
|
|
|
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
2016-01-27 08:11:54 +08:00
|
|
|
__p.__get_begin()->__next_ = __x.__before_begin()->__next_;
|
2013-06-25 01:17:28 +08:00
|
|
|
__x.__before_begin()->__next_ = nullptr;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
2016-12-24 07:37:52 +08:00
|
|
|
forward_list& /*__other*/,
|
2010-05-12 03:42:16 +08:00
|
|
|
const_iterator __i)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
const_iterator __lm1 = _VSTD::next(__i);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__p != __i && __p != __lm1)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__i.__get_begin()->__next_ = __lm1.__get_begin()->__next_;
|
|
|
|
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
|
|
|
|
__p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
2016-12-24 07:37:52 +08:00
|
|
|
forward_list& /*__other*/,
|
2010-05-12 03:42:16 +08:00
|
|
|
const_iterator __f, const_iterator __l)
|
|
|
|
{
|
|
|
|
if (__f != __l && __p != __f)
|
|
|
|
{
|
|
|
|
const_iterator __lm1 = __f;
|
2016-01-27 08:11:54 +08:00
|
|
|
while (__lm1.__get_begin()->__next_ != __l.__get_begin())
|
2010-05-12 03:42:16 +08:00
|
|
|
++__lm1;
|
|
|
|
if (__f != __lm1)
|
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
|
|
|
|
__p.__get_begin()->__next_ = __f.__get_begin()->__next_;
|
|
|
|
__f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer();
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:00:35 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
|
|
|
forward_list&& __x)
|
|
|
|
{
|
|
|
|
splice_after(__p, __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
|
|
|
forward_list&& __x,
|
|
|
|
const_iterator __i)
|
|
|
|
{
|
|
|
|
splice_after(__p, __x, __i);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
|
|
|
|
forward_list&& __x,
|
|
|
|
const_iterator __f, const_iterator __l)
|
|
|
|
{
|
|
|
|
splice_after(__p, __x, __f, __l);
|
|
|
|
}
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
template <class _Tp, class _Alloc>
|
2019-07-08 11:45:28 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::__remove_return_type
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::remove(const value_type& __v)
|
|
|
|
{
|
2019-04-17 06:11:26 +08:00
|
|
|
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
|
2019-07-02 03:22:00 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
|
|
|
|
const iterator __e = end();
|
2016-01-27 08:11:54 +08:00
|
|
|
for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
if (__i.__get_begin()->__next_->__value_ == __v)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2019-07-02 03:22:00 +08:00
|
|
|
++__count_removed;
|
2011-07-01 05:18:19 +08:00
|
|
|
iterator __j = _VSTD::next(__i, 2);
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __j != __e && *__j == __v; ++__j)
|
2019-07-02 03:22:00 +08:00
|
|
|
++__count_removed;
|
2014-10-18 19:03:33 +08:00
|
|
|
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__j == __e)
|
|
|
|
break;
|
|
|
|
__i = __j;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++__i;
|
|
|
|
}
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2019-07-08 11:45:28 +08:00
|
|
|
return (__remove_return_type) __count_removed;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _Predicate>
|
2019-07-08 11:45:28 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::__remove_return_type
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
|
|
|
|
{
|
2019-04-17 06:11:26 +08:00
|
|
|
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
|
2019-07-02 03:22:00 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
|
|
|
|
const iterator __e = end();
|
2016-01-27 08:11:54 +08:00
|
|
|
for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2016-01-27 08:11:54 +08:00
|
|
|
if (__pred(__i.__get_begin()->__next_->__value_))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
2019-07-02 03:22:00 +08:00
|
|
|
++__count_removed;
|
2011-07-01 05:18:19 +08:00
|
|
|
iterator __j = _VSTD::next(__i, 2);
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __j != __e && __pred(*__j); ++__j)
|
2019-07-02 03:22:00 +08:00
|
|
|
++__count_removed;
|
2019-04-17 06:11:26 +08:00
|
|
|
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
|
2010-05-12 03:42:16 +08:00
|
|
|
if (__j == __e)
|
|
|
|
break;
|
|
|
|
__i = __j;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++__i;
|
|
|
|
}
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2019-07-08 11:45:28 +08:00
|
|
|
return (__remove_return_type) __count_removed;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _BinaryPredicate>
|
2019-07-08 11:45:28 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::__remove_return_type
|
2010-05-12 03:42:16 +08:00
|
|
|
forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
|
|
|
|
{
|
2019-04-17 06:11:26 +08:00
|
|
|
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
|
2019-07-02 03:22:00 +08:00
|
|
|
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
|
2010-05-12 03:42:16 +08:00
|
|
|
for (iterator __i = begin(), __e = end(); __i != __e;)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
iterator __j = _VSTD::next(__i);
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
|
2019-07-02 03:22:00 +08:00
|
|
|
++__count_removed;
|
2016-01-27 08:11:54 +08:00
|
|
|
if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
|
2019-04-17 06:11:26 +08:00
|
|
|
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
|
2010-05-12 03:42:16 +08:00
|
|
|
__i = __j;
|
|
|
|
}
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2019-07-08 11:45:28 +08:00
|
|
|
return (__remove_return_type) __count_removed;
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _Compare>
|
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
|
|
|
|
{
|
2021-10-28 04:27:05 +08:00
|
|
|
if (this != _VSTD::addressof(__x))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
|
|
|
|
__x.__before_begin()->__next_,
|
|
|
|
__comp);
|
|
|
|
__x.__before_begin()->__next_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _Compare>
|
|
|
|
typename forward_list<_Tp, _Alloc>::__node_pointer
|
|
|
|
forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
|
|
|
|
_Compare& __comp)
|
|
|
|
{
|
|
|
|
if (__f1 == nullptr)
|
|
|
|
return __f2;
|
|
|
|
if (__f2 == nullptr)
|
|
|
|
return __f1;
|
|
|
|
__node_pointer __r;
|
|
|
|
if (__comp(__f2->__value_, __f1->__value_))
|
|
|
|
{
|
|
|
|
__node_pointer __t = __f2;
|
|
|
|
while (__t->__next_ != nullptr &&
|
|
|
|
__comp(__t->__next_->__value_, __f1->__value_))
|
|
|
|
__t = __t->__next_;
|
|
|
|
__r = __f2;
|
|
|
|
__f2 = __t->__next_;
|
|
|
|
__t->__next_ = __f1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__r = __f1;
|
|
|
|
__node_pointer __p = __f1;
|
|
|
|
__f1 = __f1->__next_;
|
|
|
|
while (__f1 != nullptr && __f2 != nullptr)
|
|
|
|
{
|
|
|
|
if (__comp(__f2->__value_, __f1->__value_))
|
|
|
|
{
|
|
|
|
__node_pointer __t = __f2;
|
|
|
|
while (__t->__next_ != nullptr &&
|
|
|
|
__comp(__t->__next_->__value_, __f1->__value_))
|
|
|
|
__t = __t->__next_;
|
|
|
|
__p->__next_ = __f2;
|
|
|
|
__f2 = __t->__next_;
|
|
|
|
__t->__next_ = __f1;
|
|
|
|
}
|
|
|
|
__p = __f1;
|
|
|
|
__f1 = __f1->__next_;
|
|
|
|
}
|
|
|
|
if (__f2 != nullptr)
|
|
|
|
__p->__next_ = __f2;
|
|
|
|
return __r;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _Compare>
|
2016-04-22 09:04:55 +08:00
|
|
|
inline
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
forward_list<_Tp, _Alloc>::sort(_Compare __comp)
|
|
|
|
{
|
|
|
|
base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
|
2011-07-01 05:18:19 +08:00
|
|
|
_VSTD::distance(begin(), end()), __comp);
|
2010-05-12 03:42:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
template <class _Compare>
|
|
|
|
typename forward_list<_Tp, _Alloc>::__node_pointer
|
|
|
|
forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
|
|
|
|
_Compare& __comp)
|
|
|
|
{
|
|
|
|
switch (__sz)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
return __f1;
|
|
|
|
case 2:
|
|
|
|
if (__comp(__f1->__next_->__value_, __f1->__value_))
|
|
|
|
{
|
|
|
|
__node_pointer __t = __f1->__next_;
|
|
|
|
__t->__next_ = __f1;
|
|
|
|
__f1->__next_ = nullptr;
|
|
|
|
__f1 = __t;
|
|
|
|
}
|
|
|
|
return __f1;
|
|
|
|
}
|
|
|
|
difference_type __sz1 = __sz / 2;
|
|
|
|
difference_type __sz2 = __sz - __sz1;
|
2016-01-27 08:11:54 +08:00
|
|
|
__node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer();
|
2010-05-12 03:42:16 +08:00
|
|
|
__node_pointer __f2 = __t->__next_;
|
|
|
|
__t->__next_ = nullptr;
|
|
|
|
return __merge(__sort(__f1, __sz1, __comp),
|
|
|
|
__sort(__f2, __sz2, __comp), __comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
void
|
2011-06-03 00:44:28 +08:00
|
|
|
forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__node_pointer __p = base::__before_begin()->__next_;
|
|
|
|
if (__p != nullptr)
|
|
|
|
{
|
|
|
|
__node_pointer __f = __p->__next_;
|
|
|
|
__p->__next_ = nullptr;
|
|
|
|
while (__f != nullptr)
|
|
|
|
{
|
|
|
|
__node_pointer __t = __f->__next_;
|
|
|
|
__f->__next_ = __p;
|
|
|
|
__p = __f;
|
|
|
|
__f = __t;
|
|
|
|
}
|
|
|
|
base::__before_begin()->__next_ = __p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
|
|
|
bool operator==(const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
2011-11-30 02:15:50 +08:00
|
|
|
typedef forward_list<_Tp, _Alloc> _Cp;
|
|
|
|
typedef typename _Cp::const_iterator _Ip;
|
|
|
|
_Ip __ix = __x.begin();
|
|
|
|
_Ip __ex = __x.end();
|
|
|
|
_Ip __iy = __y.begin();
|
|
|
|
_Ip __ey = __y.end();
|
2010-05-12 03:42:16 +08:00
|
|
|
for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
|
|
|
|
if (!(*__ix == *__iy))
|
|
|
|
return false;
|
|
|
|
return (__ix == __ex) == (__iy == __ey);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator!=(const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
|
|
|
return !(__x == __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator< (const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
2011-07-01 05:18:19 +08:00
|
|
|
return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
|
2010-05-12 03:42:16 +08:00
|
|
|
__y.begin(), __y.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator> (const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
|
|
|
return __y < __x;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator>=(const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
|
|
|
return !(__x < __y);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
bool operator<=(const forward_list<_Tp, _Alloc>& __x,
|
|
|
|
const forward_list<_Tp, _Alloc>& __y)
|
|
|
|
{
|
|
|
|
return !(__y < __x);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp, class _Alloc>
|
2010-09-22 06:55:27 +08:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-12 03:42:16 +08:00
|
|
|
void
|
|
|
|
swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
|
2011-06-04 00:20:53 +08:00
|
|
|
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
__x.swap(__y);
|
|
|
|
}
|
|
|
|
|
2018-12-15 02:49:35 +08:00
|
|
|
#if _LIBCPP_STD_VER > 17
|
|
|
|
template <class _Tp, class _Allocator, class _Predicate>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2020-05-02 19:58:03 +08:00
|
|
|
typename forward_list<_Tp, _Allocator>::size_type
|
|
|
|
erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
|
|
|
|
return __c.remove_if(__pred);
|
|
|
|
}
|
2018-12-15 02:49:35 +08:00
|
|
|
|
|
|
|
template <class _Tp, class _Allocator, class _Up>
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2020-05-02 19:58:03 +08:00
|
|
|
typename forward_list<_Tp, _Allocator>::size_type
|
|
|
|
erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
|
|
|
|
return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
|
|
|
|
}
|
2018-12-15 02:49:35 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2017-06-01 06:07:49 +08:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2021-04-21 00:03:32 +08:00
|
|
|
#endif // _LIBCPP_FORWARD_LIST
|