diff options
author | Paolo Carlini <pcarlini@suse.de> | 2007-11-11 11:46:10 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2007-11-11 11:46:10 +0000 |
commit | 84237dbbf3c013e9f2347414df48bcba0a328db6 (patch) | |
tree | 0184e79d28fd8a7efea4d00614f785f17738456f | |
parent | d4b5dc8945c2739a93c17b5d5b649e5c7d4179b9 (diff) | |
download | gcc-84237dbbf3c013e9f2347414df48bcba0a328db6.zip gcc-84237dbbf3c013e9f2347414df48bcba0a328db6.tar.gz gcc-84237dbbf3c013e9f2347414df48bcba0a328db6.tar.bz2 |
stl_list.h (list<>::_M_create_node<>(_Args&&...), [...]): Add.
2007-11-11 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_list.h (list<>::_M_create_node<>(_Args&&...),
_M_insert<>(iterator, _Args&&...), push_front<>(_Args&&...),
push_back<>(_Args&&...)): Add.
(list<>::emplace<>(iterator, _Args&&...), insert(iterator,
value_type&&)): Declare.
(splice(iterator, list&&), splice(iterator, list&&, iterator),
splice(iterator, list&&, iterator, iterator), merge(list&&),
merge(list&&, _StrictWeakOrdering)): Add C++0x signatures.
* include/bits/list.tcc (list<>::emplace<>(iterator, _Args&&...),
insert(iterator, value_type&&)): Define.
* include/debug/list (list<>::emplace<>(iterator, _Args&&...),
insert(iterator, value_type&&)): Add.
(splice(iterator, list&&), splice(iterator, list&&, iterator),
splice(iterator, list&&, iterator, iterator), merge(list&&),
merge(list&&, _StrictWeakOrdering)): Add C++0x signatures, use
_GLIBCXX_MOVE.
From-SVN: r130082
8 files changed, 208 insertions, 12 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c07aae4..71b9311 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2007-11-11 Paolo Carlini <pcarlini@suse.de> + + * include/bits/stl_list.h (list<>::_M_create_node<>(_Args&&...), + _M_insert<>(iterator, _Args&&...), push_front<>(_Args&&...), + push_back<>(_Args&&...)): Add. + (list<>::emplace<>(iterator, _Args&&...), insert(iterator, + value_type&&)): Declare. + (splice(iterator, list&&), splice(iterator, list&&, iterator), + splice(iterator, list&&, iterator, iterator), merge(list&&), + merge(list&&, _StrictWeakOrdering)): Add C++0x signatures. + * include/bits/list.tcc (list<>::emplace<>(iterator, _Args&&...), + insert(iterator, value_type&&)): Define. + * include/debug/list (list<>::emplace<>(iterator, _Args&&...), + insert(iterator, value_type&&)): Add. + (splice(iterator, list&&), splice(iterator, list&&, iterator), + splice(iterator, list&&, iterator, iterator), merge(list&&), + merge(list&&, _StrictWeakOrdering)): Add C++0x signatures, use + _GLIBCXX_MOVE. + 2007-11-09 Paolo Carlini <pcarlini@suse.de> * include/bits/stl_deque.h (deque<>::operator=(deque&&)): Implement diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 3fdc5bb..a7fcfb3 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -80,6 +80,19 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) } } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp, typename _Alloc> + template<typename... _Args> + typename list<_Tp, _Alloc>::iterator + list<_Tp, _Alloc>:: + emplace(iterator __position, _Args&&... __args) + { + _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); + __tmp->hook(__position._M_node); + return iterator(__tmp); + } +#endif + template<typename _Tp, typename _Alloc> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>:: @@ -90,6 +103,18 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) return iterator(__tmp); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename _Tp, typename _Alloc> + typename list<_Tp, _Alloc>::iterator + list<_Tp, _Alloc>:: + insert(iterator __position, value_type&& __x) + { + _Node* __tmp = _M_create_node(std::move(__x)); + __tmp->hook(__position._M_node); + return iterator(__tmp); + } +#endif + template<typename _Tp, typename _Alloc> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>:: @@ -220,7 +245,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) template<typename _Tp, typename _Alloc> void list<_Tp, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x) +#else merge(list& __x) +#endif { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 300. list::merge() specification incomplete @@ -250,7 +279,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) template <typename _StrictWeakOrdering> void list<_Tp, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x, _StrictWeakOrdering __comp) +#else merge(list& __x, _StrictWeakOrdering __comp) +#endif { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 300. list::merge() specification incomplete diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 41b84f3..3b143c2 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -463,6 +463,7 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Allocates space for a new node and constructs a copy of @a x in it. * @endif */ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ _Node* _M_create_node(const value_type& __x) { @@ -478,6 +479,25 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) } return __p; } +#else + template<typename... _Args> + _Node* + _M_create_node(_Args&&... __args) + { + _Node* __p = this->_M_get_node(); + try + { + _M_get_Tp_allocator().construct(&__p->_M_data, + std::forward<_Args>(__args)...); + } + catch(...) + { + _M_put_node(__p); + __throw_exception_again; + } + return __p; + } +#endif public: // [23.2.2.1] construct/copy/destroy @@ -823,9 +843,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * done in constant time, and does not invalidate iterators and * references. */ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ void push_front(const value_type& __x) { this->_M_insert(begin(), __x); } +#else + template<typename... _Args> + void + push_front(_Args&&... __args) + { this->_M_insert(begin(), std::forward<_Args>(__args)...); } +#endif /** * @brief Removes first element. @@ -853,9 +880,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * in constant time, and does not invalidate iterators and * references. */ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ void push_back(const value_type& __x) { this->_M_insert(end(), __x); } +#else + template<typename... _Args> + void + push_back(_Args&&... __args) + { this->_M_insert(end(), std::forward<_Args>(__args)...); } +#endif /** * @brief Removes last element. @@ -872,6 +906,24 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) pop_back() { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Constructs object in %list before specified iterator. + * @param position A const_iterator into the %list. + * @param args Arguments. + * @return An iterator that points to the inserted data. + * + * This function will insert an object of type T constructed + * with T(std::forward<Args>(args)...) before the specified + * location. Due to the nature of a %list this operation can + * be done in constant time, and does not invalidate iterators + * and references. + */ + template<typename... _Args> + iterator + emplace(iterator __position, _Args&&... __args); +#endif + /** * @brief Inserts given value into %list before specified iterator. * @param position An iterator into the %list. @@ -886,6 +938,22 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) iterator insert(iterator __position, const value_type& __x); +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + /** + * @brief Inserts given rvalue into %list before specified iterator. + * @param position An iterator into the %list. + * @param x Data to be inserted. + * @return An iterator that points to the inserted data. + * + * This function will insert a copy of the given rvalue before + * the specified location. Due to the nature of a %list this + * operation can be done in constant time, and does not + * invalidate iterators and references. + */ + iterator + insert(iterator __position, value_type&& __x); +#endif + /** * @brief Inserts a number of copies of given data into the %list. * @param position An iterator into the %list. @@ -1021,7 +1089,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Requires this != @a x. */ void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x) +#else splice(iterator __position, list& __x) +#endif { if (!__x.empty()) { @@ -1041,7 +1113,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * inserts it into the current list before @a position. */ void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __i) +#else splice(iterator __position, list& __x, iterator __i) +#endif { iterator __j = __i; ++__j; @@ -1067,7 +1143,13 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * Undefined if @a position is in [first,last). */ void - splice(iterator __position, list& __x, iterator __first, iterator __last) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __first, + iterator __last) +#else + splice(iterator __position, list& __x, iterator __first, + iterator __last) +#endif { if (__first != __last) { @@ -1146,7 +1228,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) * this list precede elements in @a x that are equal. */ void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x); +#else merge(list& __x); +#endif /** * @brief Merge sorted lists according to comparison function. @@ -1162,7 +1248,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) */ template<typename _StrictWeakOrdering> void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&&, _StrictWeakOrdering); +#else merge(list&, _StrictWeakOrdering); +#endif /** * @brief Reverse the elements in list. @@ -1253,12 +1343,22 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) { __position._M_node->transfer(__first._M_node, __last._M_node); } // Inserts new element at position given and with value given. +#ifndef __GXX_EXPERIMENTAL_CXX0X__ void _M_insert(iterator __position, const value_type& __x) { _Node* __tmp = _M_create_node(__x); __tmp->hook(__position._M_node); } +#else + template<typename... _Args> + void + _M_insert(iterator __position, _Args&&... __args) + { + _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); + __tmp->hook(__position._M_node); + } +#endif // Erases element at position given. void diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index 9e78fc9..9b7f33b 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -301,6 +301,17 @@ namespace __debug _Base::pop_back(); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template<typename... _Args> + iterator + emplace(iterator __position, _Args&&... __args) + { + __glibcxx_check_insert(__position); + return iterator(_Base::emplace(__position.base(), + std::forward<_Args>(__args)...), this); + } +#endif + iterator insert(iterator __position, const _Tp& __x) { @@ -308,6 +319,16 @@ namespace __debug return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(iterator __position, _Tp&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), + std::move(__x)), this); + } +#endif + void insert(iterator __position, size_type __n, const _Tp& __x) { @@ -367,16 +388,24 @@ namespace __debug // 23.2.2.4 list operations: void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x) +#else splice(iterator __position, list& __x) +#endif { _GLIBCXX_DEBUG_VERIFY(&__x != this, _M_message(__gnu_debug::__msg_self_splice) ._M_sequence(*this, "this")); - this->splice(__position, __x, __x.begin(), __x.end()); + this->splice(__position, _GLIBCXX_MOVE(__x), __x.begin(), __x.end()); } void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __i) +#else splice(iterator __position, list& __x, iterator __i) +#endif { __glibcxx_check_insert(__position); @@ -393,11 +422,18 @@ namespace __debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 250. splicing invalidates iterators this->_M_transfer_iter(__i); - _Base::splice(__position.base(), __x._M_base(), __i.base()); + _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()), + __i.base()); } void - splice(iterator __position, list& __x, iterator __first, iterator __last) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + splice(iterator __position, list&& __x, iterator __first, + iterator __last) +#else + splice(iterator __position, list& __x, iterator __first, + iterator __last) +#endif { __glibcxx_check_insert(__position); __glibcxx_check_valid_range(__first, __last); @@ -422,8 +458,8 @@ namespace __debug this->_M_transfer_iter(__victim); } - _Base::splice(__position.base(), __x._M_base(), __first.base(), - __last.base()); + _Base::splice(__position.base(), _GLIBCXX_MOVE(__x._M_base()), + __first.base(), __last.base()); } void @@ -489,7 +525,11 @@ namespace __debug } void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x) +#else merge(list& __x) +#endif { __glibcxx_check_sorted(_Base::begin(), _Base::end()); __glibcxx_check_sorted(__x.begin().base(), __x.end().base()); @@ -498,12 +538,16 @@ namespace __debug iterator __victim = __tmp++; __victim._M_attach(&__x); } - _Base::merge(__x._M_base()); + _Base::merge(_GLIBCXX_MOVE(__x._M_base())); } template<class _Compare> void +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + merge(list&& __x, _Compare __comp) +#else merge(list& __x, _Compare __comp) +#endif { __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp); __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(), @@ -513,7 +557,7 @@ namespace __debug iterator __victim = __tmp++; __victim._M_attach(&__x); } - _Base::merge(__x._M_base(), __comp); + _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp); } void diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc index 9655db0..853e930 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc @@ -19,7 +19,7 @@ // USA. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1236 } +// { dg-error "no matching" "" { target *-*-* } 1326 } // { dg-excess-errors "" } #include <list> diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc index 7899588..ea84200 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc @@ -19,7 +19,7 @@ // USA. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1205 } +// { dg-error "no matching" "" { target *-*-* } 1295 } // { dg-excess-errors "" } #include <list> diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc index 1624cf8..8283353 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc @@ -19,7 +19,7 @@ // USA. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1205 } +// { dg-error "no matching" "" { target *-*-* } 1295 } // { dg-excess-errors "" } #include <list> diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc index fddbdac..113b0b8 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc @@ -19,7 +19,7 @@ // USA. // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1205 } +// { dg-error "no matching" "" { target *-*-* } 1295 } // { dg-excess-errors "" } #include <list> |