From patchwork Sat Aug 14 01:01:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 61723 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 86B89B70D6 for ; Sat, 14 Aug 2010 11:02:03 +1000 (EST) Received: (qmail 31537 invoked by alias); 14 Aug 2010 01:01:56 -0000 Received: (qmail 31102 invoked by uid 22791); 14 Aug 2010 01:01:52 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from vsmtp14.tin.it (HELO vsmtp14.tin.it) (212.216.176.118) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 14 Aug 2010 01:01:43 +0000 Received: from [192.168.0.4] (79.43.213.160) by vsmtp14.tin.it (8.5.113) id 4BCE30370A033EEF; Sat, 14 Aug 2010 03:01:40 +0200 Message-ID: <4C65EAF3.4060200@oracle.com> Date: Sat, 14 Aug 2010 03:01:39 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100714 SUSE/3.0.6 Thunderbird/3.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] Some fixes to the unordered_containers, in particular wrt implicit move constructor and assignment operator 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, tested x86_64-linux, committed to mainline. Paolo. ////////////////////// 2010-08-13 Paolo Carlini * include/bits/hashtable.h (_Hashtable<>::operator=(const _Hashtable&)): Move inline. (operator=(_Hashtable&&)): Define. * include/bits/unordered_map.h (unordered_map(unordered_map&&), unordered_map(const unordered_map&), unordered_multimap (unordered_multimap&&), unordered_multimap(const unordered_multimap&), __unordered_map(__unordered_map&&), __unordered_map(const __unordered_map&), __unordered_multimap(__unordered_multimap&&), __unordered_multimap(const __unordered_multimap&)): Do not define, leave implicit. * include/bits/unordered_set.h (unordered_set(unordered_set&&), unordered_set(const unordered_set&), unordered_multiset (unordered_multiset&&), unordered_multiset(const unordered_multiset&), __unordered_set(__unordered_set&&), __unordered_set(const __unordered_set&), __unordered_multiset(__unordered_multiset&&), __unordered_multiset(const __unordered_multiset&)): Likewise. * include/bits/unordered_map.h (__unordered_map(initializer_list<>), __unordered_map<>::operator=(initializer_list<>), __unordered_multimap(initializer_list<>), __unordered_multimap<>:: operator=(initializer_list<>)): Add. * include/bits/unordered_set.h (__unordered_set(initializer_list<>), __unordered_set<>::operator=(initializer_list<>), __unordered_multiset(initializer_list<>), __unordered_multiset<>:: operator=(initializer_list<>)): Likewise. * include/bits/unordered_map.h (__unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_map(initializer_list<>, size_type __n), unordered_multimap(initializer_list<>, size_type __n)): Fix __n default to 0. * include/bits/unordered_set.h (__unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_set(initializer_list<>, size_type __n), unordered_multiset(initializer_list<>, size_type __n)): Likewise. * include/debug/unordered_map (unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_map(initializer_list<>, size_type __n), unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_multimap(initializer_list<>, size_type __n)): Likewise. * include/debug/unordered_set (unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_set(initializer_list<>, size_type __n), unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_multiset(initializer_list<>, size_type __n)): Likewise. * include/profile/unordered_map (unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_map(initializer_list<>, size_type __n), unordered_map(_InputIterator, _InputIterator, size_type __n), unordered_multimap(initializer_list<>, size_type __n)): Likewise. * include/profile/unordered_set (unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_set(initializer_list<>, size_type __n), unordered_set(_InputIterator, _InputIterator, size_type __n), unordered_multiset(initializer_list<>, size_type __n)): Likewise. Index: include/debug/unordered_map =================================================================== --- include/debug/unordered_map (revision 163230) +++ include/debug/unordered_map (working copy) @@ -79,7 +79,7 @@ template unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -96,7 +96,7 @@ : _Base(std::move(__x)), _Safe_base() { } unordered_map(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -338,7 +338,7 @@ template unordered_multimap(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -355,7 +355,7 @@ : _Base(std::move(__x)), _Safe_base() { } unordered_multimap(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) Index: include/debug/unordered_set =================================================================== --- include/debug/unordered_set (revision 163230) +++ include/debug/unordered_set (working copy) @@ -79,7 +79,7 @@ template unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -96,7 +96,7 @@ : _Base(std::move(__x)), _Safe_base() { } unordered_set(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -334,7 +334,7 @@ template unordered_multiset(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -351,7 +351,7 @@ : _Base(std::move(__x)), _Safe_base() { } unordered_multiset(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) Index: include/profile/unordered_map =================================================================== --- include/profile/unordered_map (revision 163230) +++ include/profile/unordered_map (working copy) @@ -86,10 +86,10 @@ template unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -111,7 +111,7 @@ } unordered_map(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -314,19 +314,19 @@ explicit unordered_multimap(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); } template unordered_multimap(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -345,7 +345,7 @@ } unordered_multimap(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) Index: include/profile/unordered_set =================================================================== --- include/profile/unordered_set (revision 163230) +++ include/profile/unordered_set (working copy) @@ -85,10 +85,10 @@ template unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -110,7 +110,7 @@ } unordered_set(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -302,9 +302,9 @@ explicit unordered_multiset(size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -312,10 +312,10 @@ template unordered_multiset(_InputIterator __f, _InputIterator __l, - size_type __n = 10, - const hasher& __hf = hasher(), - const key_equal& __eql = key_equal(), - const allocator_type& __a = allocator_type()) + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { __profcxx_hashtable_construct(this, _Base::bucket_count()); @@ -334,7 +334,7 @@ } unordered_multiset(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) Index: include/bits/hashtable.h =================================================================== --- include/bits/hashtable.h (revision 163230) +++ include/bits/hashtable.h (working copy) @@ -212,8 +212,23 @@ _Hashtable(_Hashtable&&); _Hashtable& - operator=(const _Hashtable&); + operator=(const _Hashtable& __ht) + { + _Hashtable __tmp(__ht); + this->swap(__tmp); + return *this; + } + _Hashtable& + operator=(_Hashtable&& __ht) + { + // NB: DR 1204. + // NB: DR 675. + this->clear(); + this->swap(__ht); + return *this; + } + ~_Hashtable(); void swap(_Hashtable&); @@ -668,22 +683,7 @@ typename _H1, typename _H2, typename _Hash, typename _RehashPolicy, bool __chc, bool __cit, bool __uk> _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>& - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: - operator=(const _Hashtable& __ht) - { - _Hashtable __tmp(__ht); - this->swap(__tmp); - return *this; - } - - template - _Hashtable<_Key, _Value, _Allocator, _ExtractKey, _Equal, - _H1, _H2, _Hash, _RehashPolicy, __chc, __cit, __uk>:: ~_Hashtable() { clear(); Index: include/bits/unordered_map.h =================================================================== --- include/bits/unordered_map.h (revision 163230) +++ include/bits/unordered_map.h (working copy) @@ -56,6 +56,7 @@ _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -73,7 +74,7 @@ template __unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -82,10 +83,24 @@ __eql, std::_Select1st >(), __a) { } - __unordered_map(const __unordered_map& __x) = default; + __unordered_map(initializer_list __l, + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, + __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } - __unordered_map(__unordered_map&& __x) - : _Base(std::move(__x)) { } + __unordered_map& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } }; template __unordered_multimap(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) @@ -139,10 +155,24 @@ __eql, std::_Select1st >(), __a) { } - __unordered_multimap(const __unordered_multimap& __x) = default; + __unordered_multimap(initializer_list __l, + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, + __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), + __eql, std::_Select1st >(), __a) + { } - __unordered_multimap(__unordered_multimap&& __x) - : _Base(std::move(__x)) { } + __unordered_multimap& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } }; template unordered_map(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { } - unordered_map(const unordered_map& __x) = default; - - unordered_map(unordered_map&& __x) - : _Base(std::move(__x)) { } - unordered_map(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) - : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) { } unordered_map& - operator=(const unordered_map& __x) = default; - - unordered_map& - operator=(unordered_map&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } - - unordered_map& operator=(initializer_list __l) { this->clear(); @@ -327,43 +339,24 @@ : _Base(__n, __hf, __eql, __a) { } - template unordered_multimap(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { } - unordered_multimap(const unordered_multimap& __x) = default; - - unordered_multimap(unordered_multimap&& __x) - : _Base(std::move(__x)) { } - unordered_multimap(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) - : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) { } unordered_multimap& - operator=(const unordered_multimap& __x) = default; - - unordered_multimap& - operator=(unordered_multimap&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } - - unordered_multimap& operator=(initializer_list __l) { this->clear(); Index: include/bits/unordered_set.h =================================================================== --- include/bits/unordered_set.h (revision 163230) +++ include/bits/unordered_set.h (working copy) @@ -56,6 +56,7 @@ _Base; public: + typedef typename _Base::value_type value_type; typedef typename _Base::size_type size_type; typedef typename _Base::hasher hasher; typedef typename _Base::key_equal key_equal; @@ -68,24 +69,38 @@ const allocator_type& __a = allocator_type()) : _Base(__n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) + std::_Identity(), __a) { } template __unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) + std::_Identity(), __a) { } - __unordered_set(const __unordered_set& __x) = default; + __unordered_set(initializer_list __l, + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, + __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity(), __a) + { } - __unordered_set(__unordered_set&& __x) - : _Base(std::move(__x)) { } + __unordered_set& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } }; template(), __a) + std::_Identity(), __a) { } template __unordered_multiset(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), __eql, - std::_Identity<_Value>(), __a) + std::_Identity(), __a) { } - __unordered_multiset(const __unordered_multiset& __x) = default; + __unordered_multiset(initializer_list __l, + size_type __n = 0, + const hasher& __hf = hasher(), + const key_equal& __eql = key_equal(), + const allocator_type& __a = allocator_type()) + : _Base(__l.begin(), __l.end(), __n, __hf, + __detail::_Mod_range_hashing(), + __detail::_Default_ranged_hash(), __eql, + std::_Identity(), __a) + { } - __unordered_multiset(__unordered_multiset&& __x) - : _Base(std::move(__x)) { } + __unordered_multiset& + operator=(initializer_list __l) + { + this->clear(); + this->insert(__l.begin(), __l.end()); + return *this; + } }; template unordered_set(_InputIterator __f, _InputIterator __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { } - unordered_set(const unordered_set& __x) = default; - - unordered_set(unordered_set&& __x) - : _Base(std::move(__x)) { } - unordered_set(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) - : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) { } unordered_set& - operator=(const unordered_set& __x) = default; - - unordered_set& - operator=(unordered_set&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } - - unordered_set& operator=(initializer_list __l) { this->clear(); @@ -320,40 +332,22 @@ template unordered_multiset(_InputIterator __f, _InputIterator __l, - typename _Base::size_type __n = 0, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __eql, __a) { } - unordered_multiset(const unordered_multiset& __x) = default; - - unordered_multiset(unordered_multiset&& __x) - : _Base(std::move(__x)) { } - unordered_multiset(initializer_list __l, - size_type __n = 10, + size_type __n = 0, const hasher& __hf = hasher(), const key_equal& __eql = key_equal(), const allocator_type& __a = allocator_type()) - : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) + : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a) { } unordered_multiset& - operator=(const unordered_multiset& __x) = default; - - unordered_multiset& - operator=(unordered_multiset&& __x) - { - // NB: DR 1204. - // NB: DR 675. - this->clear(); - this->swap(__x); - return *this; - } - - unordered_multiset& operator=(initializer_list __l) { this->clear();