diff options
Diffstat (limited to 'tests/libcxx/include/forward_list')
-rw-r--r-- | tests/libcxx/include/forward_list | 1526 |
1 files changed, 1526 insertions, 0 deletions
diff --git a/tests/libcxx/include/forward_list b/tests/libcxx/include/forward_list new file mode 100644 index 00000000..eed20093 --- /dev/null +++ b/tests/libcxx/include/forward_list @@ -0,0 +1,1526 @@ +// -*- C++ -*- +//===----------------------- forward_list ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#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; + + forward_list(); + explicit forward_list(const allocator_type& a); + explicit forward_list(size_type n); + 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); + forward_list(forward_list&& x); + 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); + forward_list& operator=(forward_list&& x); + 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); + + allocator_type get_allocator() const; + + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + + const_iterator cbegin() const; + const_iterator cend() const; + + iterator before_begin(); + const_iterator before_begin() const; + const_iterator cbefore_begin() const; + + bool empty() const; + size_type max_size() const; + + reference front(); + const_reference front() const; + + template <class... Args> void emplace_front(Args&&... args); + 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); + + iterator erase_after(const_iterator p); + iterator erase_after(const_iterator first, const_iterator last); + + void swap(forward_list& x); + + void resize(size_type n); + void resize(size_type n, const value_type& v); + void clear(); + + 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 first, const_iterator last); + void remove(const value_type& v); + template <class Predicate> void remove_if(Predicate pred); + void unique(); + template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); + void merge(forward_list&& x); + template <class Compare> void merge(forward_list&& x, Compare comp); + void sort(); + template <class Compare> void sort(Compare comp); + void reverse(); +}; + +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> + void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y); + +} // std + +*/ + +#include <__config> + +#include <initializer_list> +#include <memory> +#include <limits> +#include <iterator> +#include <algorithm> + +#pragma GCC system_header + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class, class> struct __forward_list_node; + +template <class _NodePtr> +struct __forward_begin_node +{ + typedef __forward_begin_node __self; + typedef _NodePtr pointer; + + pointer __next_; + + _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {} +}; + +template <class _Tp, class _VoidPtr> +struct __forward_list_node + : public __forward_begin_node + < + typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__forward_list_node<_Tp, _VoidPtr> > +#else + rebind<__forward_list_node<_Tp, _VoidPtr> >::other +#endif + > +{ + typedef _Tp value_type; + + value_type __value_; +}; + +template<class, class> class forward_list; +template<class> class __forward_list_const_iterator; + +template <class _NodePtr> +class _LIBCPP_VISIBLE __forward_list_iterator +{ + typedef _NodePtr __node_pointer; + + __node_pointer __ptr_; + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_iterator(__node_pointer __p) : __ptr_(__p) {} + + template<class, class> friend class forward_list; + template<class> friend class __forward_list_const_iterator; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename pointer_traits<__node_pointer>::element_type::value_type + value_type; + typedef value_type& reference; + typedef typename pointer_traits<__node_pointer>::difference_type + difference_type; + typedef typename pointer_traits<__node_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<value_type> +#else + rebind<value_type>::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator() : __ptr_(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator& operator++() + { + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_iterator operator++(int) + { + __forward_list_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_iterator& __x, + const __forward_list_iterator& __y) + {return !(__x == __y);} +}; + +template <class _NodeConstPtr> +class _LIBCPP_VISIBLE __forward_list_const_iterator +{ + typedef _NodeConstPtr __node_const_pointer; + + __node_const_pointer __ptr_; + + _LIBCPP_INLINE_VISIBILITY + explicit __forward_list_const_iterator(__node_const_pointer __p) + : __ptr_(__p) {} + + typedef typename remove_const + < + typename pointer_traits<__node_const_pointer>::element_type + >::type __node; + typedef typename pointer_traits<__node_const_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__node> +#else + rebind<__node>::other +#endif + __node_pointer; + + template<class, class> friend class forward_list; + +public: + typedef forward_iterator_tag iterator_category; + typedef typename __node::value_type value_type; + typedef const value_type& reference; + typedef typename pointer_traits<__node_const_pointer>::difference_type + difference_type; + typedef typename pointer_traits<__node_const_pointer>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<const value_type> +#else + rebind<const value_type>::other +#endif + pointer; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator() : __ptr_(nullptr) {} + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const {return __ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const {return &__ptr_->__value_;} + + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator& operator++() + { + __ptr_ = __ptr_->__next_; + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __forward_list_const_iterator operator++(int) + { + __forward_list_const_iterator __t(*this); + ++(*this); + return __t; + } + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __forward_list_const_iterator& __x, + const __forward_list_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __forward_list_const_iterator& __x, + 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; + + typedef typename allocator_traits<allocator_type>::void_pointer void_pointer; + typedef __forward_list_node<value_type, void_pointer> __node; + typedef typename __node::__self __begin_node; + typedef typename allocator_traits<allocator_type>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node> +#else + rebind_alloc<__node>::other +#endif + __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + typedef typename __node_traits::pointer __node_pointer; + typedef typename __node_traits::const_pointer __node_const_pointer; + + __compressed_pair<__begin_node, __node_allocator> __before_begin_; + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __before_begin() + {return pointer_traits<__node_pointer>::pointer_to( + static_cast<__node&>(__before_begin_.first()));} + _LIBCPP_INLINE_VISIBILITY + __node_const_pointer __before_begin() const + {return pointer_traits<__node_const_pointer>::pointer_to( + static_cast<const __node&>(__before_begin_.first()));} + + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __alloc() {return __before_begin_.second();} + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __alloc() const {return __before_begin_.second();} + + typedef __forward_list_iterator<__node_pointer> iterator; + typedef __forward_list_const_iterator<__node_const_pointer> const_iterator; + + _LIBCPP_INLINE_VISIBILITY + __forward_list_base() + : __before_begin_(__begin_node()) {} + _LIBCPP_INLINE_VISIBILITY + __forward_list_base(const allocator_type& __a) + : __before_begin_(__begin_node(), __node_allocator(__a)) {} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + __forward_list_base(__forward_list_base&& __x); + __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +private: + __forward_list_base(const __forward_list_base&); + __forward_list_base& operator=(const __forward_list_base&); +protected: + + ~__forward_list_base(); + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x) + {__copy_assign_alloc(__x, integral_constant<bool, + __node_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x) + {__move_assign_alloc(__x, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>());} + + void swap(__forward_list_base& __x); + void clear(); + +private: + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base&, false_type) {} + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __forward_list_base& __x, true_type) + { + if (__alloc() != __x.__alloc()) + clear(); + __alloc() = __x.__alloc(); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x, false_type) {} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__forward_list_base& __x, true_type) + {__alloc() = _STD::move(__x.__alloc());} + + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) + {__swap_alloc(__x, __y, integral_constant<bool, + __node_traits::propagate_on_container_swap::value>());} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, + false_type) + {} + _LIBCPP_INLINE_VISIBILITY + static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, + true_type) + { + using _STD::swap; + swap(__x, __y); + } +}; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) + : __before_begin_(_STD::move(__x.__before_begin_)) +{ + __x.__before_begin()->__next_ = nullptr; +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +__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; + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +__forward_list_base<_Tp, _Alloc>::~__forward_list_base() +{ + clear(); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) +{ + __swap_alloc(__alloc(), __x.__alloc()); + using _STD::swap; + swap(__before_begin()->__next_, __x.__before_begin()->__next_); +} + +template <class _Tp, class _Alloc> +void +__forward_list_base<_Tp, _Alloc>::clear() +{ + __node_allocator& __a = __alloc(); + for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) + { + __node_pointer __next = __p->__next_; + __node_traits::destroy(__a, addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); + __p = __next; + } + __before_begin()->__next_ = nullptr; +} + +template <class _Tp, class _Alloc = allocator<_Tp> > +class _LIBCPP_VISIBLE forward_list + : private __forward_list_base<_Tp, _Alloc> +{ + typedef __forward_list_base<_Tp, _Alloc> base; +public: + typedef _Tp value_type; + typedef _Alloc 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 typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + + _LIBCPP_INLINE_VISIBILITY forward_list() {} // = default; + explicit forward_list(const allocator_type& __a); + explicit forward_list(size_type __n); + 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 __f, _InputIterator __l, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + template <class _InputIterator> + forward_list(_InputIterator __f, _InputIterator __l, + const allocator_type& __a, + typename enable_if< + __is_input_iterator<_InputIterator>::value + >::type* = nullptr); + forward_list(const forward_list& __x); + forward_list(const forward_list& __x, const allocator_type& __a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + forward_list(forward_list&& __x) : base(_STD::move(__x)) {} + forward_list(forward_list&& __x, const allocator_type& __a); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + forward_list(initializer_list<value_type> __il); + forward_list(initializer_list<value_type> __il, const allocator_type& __a); + + // ~forward_list() = default; + + forward_list& operator=(const forward_list& __x); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + forward_list& operator=(forward_list&& __x); +#endif + forward_list& operator=(initializer_list<value_type> __il); + + template <class _InputIterator> + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + void + >::type + assign(_InputIterator __f, _InputIterator __l); + void assign(size_type __n, const value_type& __v); + void assign(initializer_list<value_type> __il); + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const {return allocator_type(base::__alloc());} + + _LIBCPP_INLINE_VISIBILITY + iterator begin() {return iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + iterator end() {return iterator(nullptr);} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const {return const_iterator(base::__before_begin()->__next_);} + _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const {return const_iterator(nullptr);} + + _LIBCPP_INLINE_VISIBILITY + iterator before_begin() {return iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator before_begin() const {return const_iterator(base::__before_begin());} + _LIBCPP_INLINE_VISIBILITY + const_iterator cbefore_begin() const {return const_iterator(base::__before_begin());} + + _LIBCPP_INLINE_VISIBILITY + bool empty() const {return base::__before_begin()->__next_ == nullptr;} + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const {return numeric_limits<size_type>::max();} + + _LIBCPP_INLINE_VISIBILITY + reference front() {return base::__before_begin()->__next_->__value_;} + _LIBCPP_INLINE_VISIBILITY + const_reference front() const {return base::__before_begin()->__next_->__value_;} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> void emplace_front(_Args&&... __args); +#endif + void push_front(value_type&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void push_front(const value_type& __v); + + void pop_front(); + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> + iterator emplace_after(const_iterator __p, _Args&&... __args); +#endif // _LIBCPP_HAS_NO_VARIADICS + iterator insert_after(const_iterator __p, value_type&& __v); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_input_iterator<_InputIterator>::value, + iterator + >::type + insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); + iterator insert_after(const_iterator __p, initializer_list<value_type> __il) + {return insert_after(__p, __il.begin(), __il.end());} + + iterator erase_after(const_iterator __p); + iterator erase_after(const_iterator __f, const_iterator __l); + + _LIBCPP_INLINE_VISIBILITY + void swap(forward_list& __x) {base::swap(__x);} + + void resize(size_type __n); + void resize(size_type __n, const value_type& __v); + _LIBCPP_INLINE_VISIBILITY + void clear() {base::clear();} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + void remove(const value_type& __v); + template <class _Predicate> void remove_if(_Predicate __pred); + _LIBCPP_INLINE_VISIBILITY + void unique() {unique(__equal_to<value_type>());} + template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list&& __x) {merge(_STD::move(__x), __less<value_type>());} + template <class _Compare> void merge(forward_list&& __x, _Compare __comp); +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void merge(forward_list& __x) {merge(__x, __less<value_type>());} + template <class _Compare> void merge(forward_list& __x, _Compare __comp); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY + void sort() {sort(__less<value_type>());} + template <class _Compare> void sort(_Compare __comp); + void reverse(); + +private: + typedef typename base::__node_allocator __node_allocator; + typedef typename base::__node __node; + typedef typename base::__node_traits __node_traits; + typedef typename base::__node_pointer __node_pointer; + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + void __move_assign(forward_list& __x, true_type); + void __move_assign(forward_list& __x, false_type); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + + 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); +}; + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +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(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); + for (__node_pointer __p = base::__before_begin(); __n > 0; --__n, + __p = __p->__next_) + { + __h.reset(__node_traits::allocate(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_)); + __h->__next_ = nullptr; + __p->__next_ = __h.release(); + } + } +} + +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> +forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v, + const allocator_type& __a) + : base(__a) +{ + 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< + __is_input_iterator<_InputIterator>::value + >::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< + __is_input_iterator<_InputIterator>::value + >::type*) + : base(__a) +{ + insert_after(cbefore_begin(), __f, __l); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x) + : base(allocator_type( + __node_traits::select_on_container_copy_construction(__x.__alloc()) + ) + ) +{ + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, + const allocator_type& __a) + : base(__a) +{ + insert_after(cbefore_begin(), __x.begin(), __x.end()); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, + const allocator_type& __a) + : base(_STD::move(__x), __a) +{ + if (base::__alloc() != __x.__alloc()) + { + typedef move_iterator<iterator> _I; + insert_after(cbefore_begin(), _I(__x.begin()), _I(__x.end())); + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +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> +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) +{ + if (this != &__x) + { + base::__copy_assign_alloc(__x); + assign(__x.begin(), __x.end()); + } + return *this; +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) +{ + 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 + { + typedef move_iterator<iterator> _I; + assign(_I(__x.begin()), _I(__x.end())); + } +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) +{ + __move_assign(__x, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +forward_list<_Tp, _Alloc>& +forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) +{ + assign(__il.begin(), __il.end()); + return *this; +} + +template <class _Tp, class _Alloc> +template <class _InputIterator> +typename enable_if +< + __is_input_iterator<_InputIterator>::value, + void +>::type +forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) +{ + iterator __i = before_begin(); + iterator __j = next(__i); + iterator __e = end(); + for (; __j != __e && __f != __l; ++__i, ++__j, ++__f) + *__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(); + iterator __j = next(__i); + 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); +} + +template <class _Tp, class _Alloc> +inline _LIBCPP_INLINE_VISIBILITY +void +forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) +{ + assign(__il.begin(), __il.end()); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class _Alloc> +template <class... _Args> +void +forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_), + _STD::forward<_Args>(__args)...); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::push_front(value_type&& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_), _STD::move(__v)); + __h->__next_ = base::__before_begin()->__next_; + base::__before_begin()->__next_ = __h.release(); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +void +forward_list<_Tp, _Alloc>::push_front(const value_type& __v) +{ + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_), __v); + __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_; + __node_traits::destroy(__a, addressof(__p->__value_)); + __node_traits::deallocate(__a, __p, 1); +} + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + +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) +{ + __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_), + _STD::forward<_Args>(__args)...); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) +{ + __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); + __node_allocator& __a = base::__alloc(); + typedef __allocator_destructor<__node_allocator> _D; + unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); + __node_traits::construct(__a, addressof(__h->__value_), _STD::move(__v)); + __h->__next_ = __r->__next_; + __r->__next_ = __h.release(); + return iterator(__r->__next_); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class _Tp, class _Alloc> +typename forward_list<_Tp, _Alloc>::iterator +forward_list<_Tp, _Alloc>::insert |