From patchwork Wed Nov 10 19:11:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 70683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BD697B70CD for ; Thu, 11 Nov 2010 06:12:30 +1100 (EST) Received: (qmail 8623 invoked by alias); 10 Nov 2010 19:12:27 -0000 Received: (qmail 8567 invoked by uid 22791); 10 Nov 2010 19:12:16 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp12.tin.it (HELO vsmtp12.tin.it) (212.216.176.206) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 10 Nov 2010 19:12:03 +0000 Received: from [192.168.0.4] (79.33.222.77) by vsmtp12.tin.it (8.5.113) id 4BC85B9710D0A094; Wed, 10 Nov 2010 20:11:59 +0100 Message-ID: <4CDAEE7E.4010308@oracle.com> Date: Wed, 10 Nov 2010 20:11:58 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.15) Gecko/20101026 SUSE/3.0.10 Thunderbird/3.0.10 MIME-Version: 1.0 To: libstdc++ CC: "gcc-patches@gcc.gnu.org" Subject: [v3] More of libstdc++/44436 (fix 46148) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, reasonably, I don't think we can do even more of 44436 for 4.6.0, also given open LWG issues about the emplace members. Tested x86_64-linux, committed. Paolo. /////////////////////// 2010-11-10 Paolo Carlini PR libstdc++/44436 (partial) PR libstdc++/46148 * include/bits/stl_tree.h (_Rb_tree<>::_M_insert_, _M_insert_lower, _M_insert_equal_lower, _M_insert_unique, _M_insert_equal, _M_insert_unique_, _M_insert_equal_): Templatize in C++0x mode, use _GLIBCXX_FORWARD throughout. * include/bits/stl_map.h (map<>::insert(_Pair&&), insert(const_iterator, _Pair&&), operator[](key_type&&): Add. * include/bits/stl_set.h (set<>::insert(value_type&&), insert(const_iterator, value_type&&)): Likewise. * include/bits/stl_multimap.h (multimap<>::insert(_Pair&&), insert(const_iterator, _Pair&&)): Likewise. * include/bits/stl_multiset.h (multiset<>::insert(value_type&&), insert(const_iterator, value_type&&)): Likewise. * include/debug/set.h: Adjust. * include/debug/multiset.h: Likewise. * include/debug/map.h: Likewise. * include/debug/multimap.h: Likewise. * include/profile/set.h: Likewise. * include/profile/multiset.h: Likewise. * include/profile/map.h: Likewise. * include/profile/multimap.h: Likewise. * testsuite/23_containers/multimap/modifiers/insert/1.cc: New. * testsuite/23_containers/multimap/modifiers/insert/2.cc: Likewise. * testsuite/23_containers/multimap/modifiers/insert/3.cc: Likewise. * testsuite/23_containers/multimap/modifiers/insert/4.cc: Likewise. * testsuite/23_containers/set/modifiers/insert/2.cc: Likewise. * testsuite/23_containers/set/modifiers/insert/3.cc: Likewise. * testsuite/23_containers/multiset/modifiers/insert/3.cc: Likewise. * testsuite/23_containers/multiset/modifiers/insert/4.cc: Likewise. * testsuite/23_containers/map/modifiers/insert/2.cc: Likewise. * testsuite/23_containers/map/modifiers/insert/3.cc: Likewise. * testsuite/23_containers/map/modifiers/insert/4.cc: Likewise. * testsuite/23_containers/map/modifiers/insert/5.cc: Likewise. * testsuite/23_containers/map/element_access/2.cc: Likewise. * testsuite/23_containers/map/element_access/46148.cc: Likewise. * include/bits/hashtable.h: Trivial naming changes. Index: include/debug/set.h =================================================================== --- include/debug/set.h (revision 166538) +++ include/debug/set.h (working copy) @@ -199,6 +199,18 @@ __res.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair + insert(value_type&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::move(__x)); + return std::pair(iterator(__res.first, this), + __res.second); + } +#endif + iterator insert(iterator __position, const value_type& __x) { @@ -206,6 +218,16 @@ return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), std::move(__x)), + this); + } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/debug/multiset.h =================================================================== --- include/debug/multiset.h (revision 166538) +++ include/debug/multiset.h (working copy) @@ -194,13 +194,29 @@ insert(const value_type& __x) { return iterator(_Base::insert(__x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator + insert(value_type&& __x) + { return iterator(_Base::insert(std::move(__x)), this); } +#endif + + iterator insert(iterator __position, const value_type& __x) { __glibcxx_check_insert(__position); return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), std::move(__x)), + this); + } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/debug/map.h =================================================================== --- include/debug/map.h (revision 166538) +++ include/debug/map.h (working copy) @@ -211,6 +211,21 @@ } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + std::pair + insert(_Pair&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::forward<_Pair>(__x)); + return std::pair(iterator(__res.first, this), + __res.second); + } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list __list) { _Base::insert(__list); } @@ -223,6 +238,19 @@ return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), + std::forward<_Pair>(__x)), this); + } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/debug/multimap.h =================================================================== --- include/debug/multimap.h (revision 166538) +++ include/debug/multimap.h (working copy) @@ -198,6 +198,15 @@ { return iterator(_Base::insert(__x), this); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(_Pair&& __x) + { return iterator(_Base::insert(std::forward<_Pair>(__x)), this); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list __list) { _Base::insert(__list); } @@ -210,6 +219,19 @@ return iterator(_Base::insert(__position.base(), __x), this); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + __glibcxx_check_insert(__position); + return iterator(_Base::insert(__position.base(), + std::forward<_Pair>(__x)), this); + } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/profile/set.h =================================================================== --- include/profile/set.h (revision 166538) +++ include/profile/set.h (working copy) @@ -188,6 +188,18 @@ __res.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair + insert(value_type&& __x) + { + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::move(__x)); + return std::pair(iterator(__res.first), + __res.second); + } +#endif + iterator #ifdef __GXX_EXPERIMENTAL_CXX0X__ insert(const_iterator __position, const value_type& __x) @@ -196,6 +208,12 @@ #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return iterator(_Base::insert(__position, std::move(__x))); } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/profile/multiset.h =================================================================== --- include/profile/multiset.h (revision 166538) +++ include/profile/multiset.h (working copy) @@ -183,7 +183,13 @@ insert(const value_type& __x) { return iterator(_Base::insert(__x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ iterator + insert(value_type&& __x) + { return iterator(_Base::insert(std::move(__x))); } +#endif + + iterator #ifdef __GXX_EXPERIMENTAL_CXX0X__ insert(const_iterator __position, const value_type& __x) #else @@ -191,6 +197,12 @@ #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return iterator(_Base::insert(__position, std::move(__x))); } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/profile/map.h =================================================================== --- include/profile/map.h (revision 166538) +++ include/profile/map.h (working copy) @@ -219,7 +219,16 @@ return _Base::operator[](__k); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ mapped_type& + operator[](key_type&& __k) + { + __profcxx_map_to_unordered_map_find(this, size()); + return _Base::operator[](std::move(__k)); + } +#endif + + mapped_type& at(const key_type& __k) { __profcxx_map_to_unordered_map_find(this, size()); @@ -245,6 +254,22 @@ } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + std::pair + insert(_Pair&& __x) + { + __profcxx_map_to_unordered_map_insert(this, size(), 1); + typedef typename _Base::iterator _Base_iterator; + std::pair<_Base_iterator, bool> __res + = _Base::insert(std::forward<_Pair>(__x)); + return std::pair(iterator(__res.first), + __res.second); + } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list __list) { @@ -269,6 +294,22 @@ return __i; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { + size_type size_before = size(); + iterator __i + = iterator(_Base::insert(__position, std::forward<_Pair>(__x))); + __profcxx_map_to_unordered_map_insert(this, size_before, + size() - size_before); + return __i; + } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/profile/multimap.h =================================================================== --- include/profile/multimap.h (revision 166538) +++ include/profile/multimap.h (working copy) @@ -186,6 +186,15 @@ { return iterator(_Base::insert(__x)); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(_Pair&& __x) + { return iterator(_Base::insert(std::forward<_Pair>(__x))); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ void insert(std::initializer_list __list) { _Base::insert(__list); } @@ -199,6 +208,16 @@ #endif { return iterator(_Base::insert(__position, __x)); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return iterator(_Base::insert(__position, + std::forward<_Pair>(__x))); } +#endif + template void insert(_InputIterator __first, _InputIterator __last) Index: include/bits/hashtable.h =================================================================== --- include/bits/hashtable.h (revision 166538) +++ include/bits/hashtable.h (working copy) @@ -367,18 +367,18 @@ _M_find_node(_Node*, const key_type&, typename _Hashtable::_Hash_code_type) const; - template + template iterator - _M_insert_bucket(_Pair&&, size_type, + _M_insert_bucket(_Arg&&, size_type, typename _Hashtable::_Hash_code_type); - template + template std::pair - _M_insert(_Pair&&, std::true_type); + _M_insert(_Arg&&, std::true_type); - template + template iterator - _M_insert(_Pair&&, std::false_type); + _M_insert(_Arg&&, std::false_type); typedef typename std::conditional<__unique_keys, std::pair, @@ -898,13 +898,13 @@ typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template + template typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::iterator _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert_bucket(_Pair&& __v, size_type __n, + _M_insert_bucket(_Arg&& __v, size_type __n, typename _Hashtable::_Hash_code_type __code) { std::pair __do_rehash @@ -919,7 +919,7 @@ // Allocate the new node before doing the rehash so that we don't // do a rehash if the allocation throws. - _Node* __new_node = _M_allocate_node(std::forward<_Pair>(__v)); + _Node* __new_node = _M_allocate_node(std::forward<_Arg>(__v)); __try { @@ -946,14 +946,14 @@ typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template + template std::pair::iterator, bool> _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(_Pair&& __v, std::true_type) + _M_insert(_Arg&& __v, std::true_type) { const key_type& __k = this->_M_extract(__v); typename _Hashtable::_Hash_code_type __code = this->_M_hash_code(__k); @@ -961,7 +961,7 @@ if (_Node* __p = _M_find_node(_M_buckets[__n], __k, __code)) return std::make_pair(iterator(__p, _M_buckets + __n), false); - return std::make_pair(_M_insert_bucket(std::forward<_Pair>(__v), + return std::make_pair(_M_insert_bucket(std::forward<_Arg>(__v), __n, __code), true); } @@ -970,13 +970,13 @@ typename _Allocator, typename _ExtractKey, typename _Equal, typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> - template + template typename _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>::iterator _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - _M_insert(_Pair&& __v, std::false_type) + _M_insert(_Arg&& __v, std::false_type) { std::pair __do_rehash = _M_rehash_policy._M_need_rehash(_M_bucket_count, @@ -990,7 +990,7 @@ // First find the node, avoid leaking new_node if compare throws. _Node* __prev = _M_find_node(_M_buckets[__n], __k, __code); - _Node* __new_node = _M_allocate_node(std::forward<_Pair>(__v)); + _Node* __new_node = _M_allocate_node(std::forward<_Arg>(__v)); if (__prev) { Index: include/bits/stl_map.h =================================================================== --- include/bits/stl_map.h (revision 166538) +++ include/bits/stl_map.h (working copy) @@ -452,6 +452,21 @@ return (*__i).second; } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + mapped_type& + operator[](key_type&& __k) + { + // concept requirements + __glibcxx_function_requires(_DefaultConstructibleConcept) + + iterator __i = lower_bound(__k); + // __i->first is greater than or equivalent to __k. + if (__i == end() || key_comp()(__k, (*__i).first)) + __i = insert(__i, std::make_pair(std::move(__k), mapped_type())); + return (*__i).second; + } +#endif + // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. /** @@ -501,6 +516,15 @@ { return _M_t._M_insert_unique(__x); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + std::pair + insert(_Pair&& __x) + { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); } +#endif + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief Attempts to insert a list of std::pairs into the %map. * @param list A std::initializer_list of pairs to be @@ -544,6 +568,16 @@ #endif { return _M_t._M_insert_unique_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return _M_t._M_insert_unique_(__position, + std::forward<_Pair>(__x)); } +#endif + /** * @brief Template function that attempts to insert a range of elements. * @param first Iterator pointing to the start of the range to be Index: include/bits/stl_set.h =================================================================== --- include/bits/stl_set.h (revision 166538) +++ include/bits/stl_set.h (working copy) @@ -124,7 +124,7 @@ typedef typename _Rep_type::const_iterator iterator; typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_reverse_iterator reverse_iterator; - typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; + typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type; //@} @@ -409,6 +409,16 @@ return std::pair(__p.first, __p.second); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + std::pair + insert(value_type&& __x) + { + std::pair __p = + _M_t._M_insert_unique(std::move(__x)); + return std::pair(__p.first, __p.second); + } +#endif + /** * @brief Attempts to insert an element into the %set. * @param position An iterator that serves as a hint as to where the @@ -436,6 +446,12 @@ #endif { return _M_t._M_insert_unique_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return _M_t._M_insert_unique_(__position, std::move(__x)); } +#endif + /** * @brief A template function that attempts to insert a range * of elements. Index: include/bits/stl_multimap.h =================================================================== --- include/bits/stl_multimap.h (revision 166538) +++ include/bits/stl_multimap.h (working copy) @@ -438,6 +438,15 @@ insert(const value_type& __x) { return _M_t._M_insert_equal(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(_Pair&& __x) + { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); } +#endif + /** * @brief Inserts a std::pair into the %multimap. * @param position An iterator that serves as a hint as to where the @@ -466,6 +475,16 @@ #endif { return _M_t._M_insert_equal_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template::value>::type> + iterator + insert(const_iterator __position, _Pair&& __x) + { return _M_t._M_insert_equal_(__position, + std::forward<_Pair>(__x)); } +#endif + /** * @brief A template function that attempts to insert a range * of elements. Index: include/bits/stl_multiset.h =================================================================== --- include/bits/stl_multiset.h (revision 166538) +++ include/bits/stl_multiset.h (working copy) @@ -118,7 +118,7 @@ typedef typename _Rep_type::const_iterator iterator; typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_reverse_iterator reverse_iterator; - typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; + typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type; @@ -396,6 +396,12 @@ insert(const value_type& __x) { return _M_t._M_insert_equal(__x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(value_type&& __x) + { return _M_t._M_insert_equal(std::move(__x)); } +#endif + /** * @brief Inserts an element into the %multiset. * @param position An iterator that serves as a hint as to where the @@ -424,6 +430,12 @@ #endif { return _M_t._M_insert_equal_(__position, __x); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + iterator + insert(const_iterator __position, value_type&& __x) + { return _M_t._M_insert_equal_(__position, std::move(__x)); } +#endif + /** * @brief A template function that tries to insert a range of elements. * @param first Iterator pointing to the start of the range to be Index: include/bits/stl_tree.h =================================================================== --- include/bits/stl_tree.h (revision 166538) +++ include/bits/stl_tree.h (working copy) @@ -561,6 +561,19 @@ { return iterator(static_cast<_Link_type> (const_cast<_Base_ptr>(__cit._M_node))); } +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + iterator + _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __y, _Arg&& __v); + + template + iterator + _M_insert_lower(_Base_ptr __x, _Base_ptr __y, _Arg&& __v); + + template + iterator + _M_insert_equal_lower(_Arg&& __x); +#else iterator _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __y, const value_type& __v); @@ -572,6 +585,7 @@ iterator _M_insert_equal_lower(const value_type& __x); +#endif _Link_type _M_copy(_Const_Link_type __x, _Link_type __p); @@ -687,6 +701,23 @@ swap(_Rb_tree& __t); // Insert/erase. +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + pair + _M_insert_unique(_Arg&& __x); + + template + iterator + _M_insert_equal(_Arg&& __x); + + template + iterator + _M_insert_unique_(const_iterator __position, _Arg&& __x); + + template + iterator + _M_insert_equal_(const_iterator __position, _Arg&& __x); +#else pair _M_insert_unique(const value_type& __x); @@ -698,6 +729,7 @@ iterator _M_insert_equal_(const_iterator __position, const value_type& __x); +#endif template void @@ -901,15 +933,22 @@ template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, _Arg&& __v) +#else _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, const _Val& __v) +#endif { bool __insert_left = (__x != 0 || __p == _M_end() || _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__p))); - _Link_type __z = _M_create_node(__v); + _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)); _Rb_tree_insert_and_rebalance(__insert_left, __z, const_cast<_Base_ptr>(__p), @@ -920,15 +959,22 @@ template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_lower(_Base_ptr __x, _Base_ptr __p, _Arg&& __v) +#else _M_insert_lower(_Base_ptr __x, _Base_ptr __p, const _Val& __v) +#endif { bool __insert_left = (__x != 0 || __p == _M_end() || !_M_impl._M_key_compare(_S_key(__p), _KeyOfValue()(__v))); - _Link_type __z = _M_create_node(__v); + _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)); _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, this->_M_impl._M_header); @@ -938,9 +984,16 @@ template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal_lower(_Arg&& __v) +#else _M_insert_equal_lower(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -950,7 +1003,7 @@ __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ? _S_left(__x) : _S_right(__x); } - return _M_insert_lower(__x, __y, __v); + return _M_insert_lower(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)); } template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif pair::iterator, bool> _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_unique(_Arg&& __v) +#else _M_insert_unique(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -1201,20 +1261,29 @@ if (__comp) { if (__j == begin()) - return pair(_M_insert_(__x, __y, __v), true); + return pair + (_M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)), true); else --__j; } if (_M_impl._M_key_compare(_S_key(__j._M_node), _KeyOfValue()(__v))) - return pair(_M_insert_(__x, __y, __v), true); + return pair + (_M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)), true); return pair(__j, false); } template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal(_Arg&& __v) +#else _M_insert_equal(const _Val& __v) +#endif { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -1224,14 +1293,21 @@ __x = _M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__x)) ? _S_left(__x) : _S_right(__x); } - return _M_insert_(__x, __y, __v); + return _M_insert_(__x, __y, _GLIBCXX_FORWARD(_Arg, __v)); } template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_unique_(const_iterator __position, _Arg&& __v) +#else _M_insert_unique_(const_iterator __position, const _Val& __v) +#endif { // end() if (__position._M_node == _M_end()) @@ -1239,9 +1315,9 @@ if (size() > 0 && _M_impl._M_key_compare(_S_key(_M_rightmost()), _KeyOfValue()(__v))) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else if (_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(__position._M_node))) @@ -1249,18 +1325,21 @@ // First, try before... const_iterator __before = __position; if (__position._M_node == _M_leftmost()) // begin() - return _M_insert_(_M_leftmost(), _M_leftmost(), __v); + return _M_insert_(_M_leftmost(), _M_leftmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), _KeyOfValue()(__v))) { if (_S_right(__before._M_node) == 0) - return _M_insert_(0, __before._M_node, __v); + return _M_insert_(0, __before._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else return _M_insert_(__position._M_node, - __position._M_node, __v); + __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else if (_M_impl._M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) @@ -1268,17 +1347,20 @@ // ... then try after. const_iterator __after = __position; if (__position._M_node == _M_rightmost()) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key((++__after)._M_node))) { if (_S_right(__position._M_node) == 0) - return _M_insert_(0, __position._M_node, __v); + return _M_insert_(0, __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_(__after._M_node, __after._M_node, __v); + return _M_insert_(__after._M_node, __after._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_unique(__v).first; + return _M_insert_unique(_GLIBCXX_FORWARD(_Arg, __v)).first; } else // Equivalent keys. @@ -1287,9 +1369,16 @@ template +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template +#endif typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + _M_insert_equal_(const_iterator __position, _Arg&& __v) +#else _M_insert_equal_(const_iterator __position, const _Val& __v) +#endif { // end() if (__position._M_node == _M_end()) @@ -1297,9 +1386,10 @@ if (size() > 0 && !_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key(_M_rightmost()))) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_equal(__v); + return _M_insert_equal(_GLIBCXX_FORWARD(_Arg, __v)); } else if (!_M_impl._M_key_compare(_S_key(__position._M_node), _KeyOfValue()(__v))) @@ -1307,35 +1397,41 @@ // First, try before... const_iterator __before = __position; if (__position._M_node == _M_leftmost()) // begin() - return _M_insert_(_M_leftmost(), _M_leftmost(), __v); + return _M_insert_(_M_leftmost(), _M_leftmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (!_M_impl._M_key_compare(_KeyOfValue()(__v), _S_key((--__before)._M_node))) { if (_S_right(__before._M_node) == 0) - return _M_insert_(0, __before._M_node, __v); + return _M_insert_(0, __before._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else return _M_insert_(__position._M_node, - __position._M_node, __v); + __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_equal(__v); + return _M_insert_equal(_GLIBCXX_FORWARD(_Arg, __v)); } else { // ... then try after. const_iterator __after = __position; if (__position._M_node == _M_rightmost()) - return _M_insert_(0, _M_rightmost(), __v); + return _M_insert_(0, _M_rightmost(), + _GLIBCXX_FORWARD(_Arg, __v)); else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), _KeyOfValue()(__v))) { if (_S_right(__position._M_node) == 0) - return _M_insert_(0, __position._M_node, __v); + return _M_insert_(0, __position._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); else - return _M_insert_(__after._M_node, __after._M_node, __v); + return _M_insert_(__after._M_node, __after._M_node, + _GLIBCXX_FORWARD(_Arg, __v)); } else - return _M_insert_equal_lower(__v); + return _M_insert_equal_lower(_GLIBCXX_FORWARD(_Arg, __v)); } } Index: testsuite/23_containers/multimap/modifiers/insert/1.cc =================================================================== --- testsuite/23_containers/multimap/modifiers/insert/1.cc (revision 0) +++ testsuite/23_containers/multimap/modifiers/insert/1.cc (revision 0) @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(2, rvalstruct(3))); + m.insert(Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/multimap/modifiers/insert/2.cc =================================================================== --- testsuite/23_containers/multimap/modifiers/insert/2.cc (revision 0) +++ testsuite/23_containers/multimap/modifiers/insert/2.cc (revision 0) @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 3 && (i2->second).val == 7 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/multimap/modifiers/insert/3.cc =================================================================== --- testsuite/23_containers/multimap/modifiers/insert/3.cc (revision 0) +++ testsuite/23_containers/multimap/modifiers/insert/3.cc (revision 0) @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( i->first == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + m.insert(i0, Pair(2, rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( i1->first == 2 ); + VERIFY( i2->first == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/multimap/modifiers/insert/4.cc =================================================================== --- testsuite/23_containers/multimap/modifiers/insert/4.cc (revision 0) +++ testsuite/23_containers/multimap/modifiers/insert/4.cc (revision 0) @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i = m.insert(m.begin(), + Pair(rvalstruct(1), rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( i == m.begin() ); + VERIFY( (i->first).val == 1 ); + VERIFY( (i->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multimap Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator i0 = m.insert(Pair(rvalstruct(2), rvalstruct(3))); + m.insert(i0, Pair(rvalstruct(2), rvalstruct(7))); + + VERIFY( m.size() == 2 ); + VERIFY( std::distance(m.begin(), m.end()) == 2 ); + + Map::iterator i1 = m.begin(); + Map::iterator i2 = i1; + ++i2; + + VERIFY( (i1->first).val == 2 ); + VERIFY( (i2->first).val == 2 ); + VERIFY( (i1->second).val == 7 && (i2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/set/modifiers/insert/2.cc =================================================================== --- testsuite/23_containers/set/modifiers/insert/2.cc (revision 0) +++ testsuite/23_containers/set/modifiers/insert/2.cc (revision 0) @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set Set; + Set s; + VERIFY( s.empty() ); + + std::pair p = s.insert(rvalstruct(1)); + VERIFY( p.second ); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p.first == s.begin() ); + VERIFY( (*p.first).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set Set; + Set s; + VERIFY( s.empty() ); + + std::pair p1 = s.insert(rvalstruct(2)); + std::pair p2 = s.insert(rvalstruct(2)); + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( s.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (*p1.first).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/set/modifiers/insert/3.cc =================================================================== --- testsuite/23_containers/set/modifiers/insert/3.cc (revision 0) +++ testsuite/23_containers/set/modifiers/insert/3.cc (revision 0) @@ -0,0 +1,64 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( p == s.begin() ); + VERIFY( (*p).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::set Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator p1 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator p2 = s.insert(p1, rvalstruct(2)); + VERIFY( s.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (*p1).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/multiset/modifiers/insert/3.cc =================================================================== --- testsuite/23_containers/multiset/modifiers/insert/3.cc (revision 0) +++ testsuite/23_containers/multiset/modifiers/insert/3.cc (revision 0) @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset Set; + Set s; + VERIFY( s.empty() ); + + s.insert(rvalstruct(2)); + Set::iterator i = s.insert(rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i == s.begin() || i == i2 ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/multiset/modifiers/insert/4.cc =================================================================== --- testsuite/23_containers/multiset/modifiers/insert/4.cc (revision 0) +++ testsuite/23_containers/multiset/modifiers/insert/4.cc (revision 0) @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i = s.insert(s.begin(), rvalstruct(1)); + VERIFY( s.size() == 1 ); + VERIFY( std::distance(s.begin(), s.end()) == 1 ); + VERIFY( i == s.begin() ); + VERIFY( (*i).val == 1 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::multiset Set; + Set s; + VERIFY( s.empty() ); + + Set::iterator i0 = s.insert(s.begin(), rvalstruct(2)); + Set::iterator i1 = s.insert(i0, rvalstruct(2)); + VERIFY( s.size() == 2 ); + VERIFY( std::distance(s.begin(), s.end()) == 2 ); + VERIFY( (*i1).val == 2 ); + + Set::iterator i2 = s.begin(); + ++i2; + VERIFY( i1 == s.begin() ); + VERIFY( (*(s.begin())).val == 2 && (*i2).val == 2 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/map/modifiers/insert/2.cc =================================================================== --- testsuite/23_containers/map/modifiers/insert/2.cc (revision 0) +++ testsuite/23_containers/map/modifiers/insert/2.cc (revision 0) @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty()); + + std::pair p = m.insert(Pair(1, rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( p.first->first == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair p1 = m.insert(Pair(2, rvalstruct(3))); + std::pair p2 = m.insert(Pair(2, rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( p1.first->first == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/map/modifiers/insert/3.cc =================================================================== --- testsuite/23_containers/map/modifiers/insert/3.cc (revision 0) +++ testsuite/23_containers/map/modifiers/insert/3.cc (revision 0) @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty()); + + std::pair p = m.insert(Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( p.second ); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p.first == m.begin() ); + VERIFY( (p.first->first).val == 1 ); + VERIFY( (p.first->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + std::pair p1 = m.insert(Pair(rvalstruct(2), + rvalstruct(3))); + std::pair p2 = m.insert(Pair(rvalstruct(2), + rvalstruct(7))); + + VERIFY( p1.second ); + VERIFY( !p2.second ); + VERIFY( m.size() == 1 ); + VERIFY( p1.first == p2.first ); + VERIFY( (p1.first->first).val == 2 ); + VERIFY( (p2.first->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/map/modifiers/insert/4.cc =================================================================== --- testsuite/23_containers/map/modifiers/insert/4.cc (revision 0) +++ testsuite/23_containers/map/modifiers/insert/4.cc (revision 0) @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(1, rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( p->first == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(2, rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(2, rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( p1->first == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/map/modifiers/insert/5.cc =================================================================== --- testsuite/23_containers/map/modifiers/insert/5.cc (revision 0) +++ testsuite/23_containers/map/modifiers/insert/5.cc (revision 0) @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty()); + + Map::iterator p = m.insert(m.begin(), Pair(rvalstruct(1), + rvalstruct(3))); + VERIFY( m.size() == 1 ); + VERIFY( std::distance(m.begin(), m.end()) == 1 ); + VERIFY( p == m.begin() ); + VERIFY( (p->first).val == 1 ); + VERIFY( (p->second).val == 3 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + typedef std::pair Pair; + + Map m; + VERIFY( m.empty() ); + + Map::iterator p1 = m.insert(m.begin(), Pair(rvalstruct(2), + rvalstruct(3))); + Map::iterator p2 = m.insert(p1, Pair(rvalstruct(2), + rvalstruct(7))); + VERIFY( m.size() == 1 ); + VERIFY( p1 == p2 ); + VERIFY( (p1->first).val == 2 ); + VERIFY( (p2->second).val == 3 ); +} + +int main() +{ + test01(); + test02(); + return 0; +} Index: testsuite/23_containers/map/element_access/2.cc =================================================================== --- testsuite/23_containers/map/element_access/2.cc (revision 0) +++ testsuite/23_containers/map/element_access/2.cc (revision 0) @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-11-10 Paolo Carlini +// +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::rvalstruct; + + typedef std::map Map; + + Map m; + VERIFY( m.empty() ); + + m[rvalstruct(1)] = rvalstruct(17); + VERIFY( m.size() == 1 ); + VERIFY( (m.begin()->first).val == 1 ); + VERIFY( (m.begin()->second).val == 17 ); + VERIFY( m[rvalstruct(1)].val == 17 ); + + m[rvalstruct(2)] = rvalstruct(9); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(2)].val == 9 ); + + m[rvalstruct(1)] = rvalstruct(5); + VERIFY( m.size() == 2 ); + VERIFY( m[rvalstruct(1)].val == 5 ); + VERIFY( m[rvalstruct(2)].val == 9 ); +} + +int main() +{ + test01(); + return 0; +} Index: testsuite/23_containers/map/element_access/46148.cc =================================================================== --- testsuite/23_containers/map/element_access/46148.cc (revision 0) +++ testsuite/23_containers/map/element_access/46148.cc (revision 0) @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +class moveable +{ +public: + moveable(moveable&&) { } + moveable() { } + + operator int() + { return 0; } +}; + +// libstdc++/46148 +int main() +{ + std::map the_map; + return the_map[true]; +}