From patchwork Fri Oct 29 15:09:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 69602 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 00076B70DC for ; Sat, 30 Oct 2010 02:10:10 +1100 (EST) Received: (qmail 19111 invoked by alias); 29 Oct 2010 15:10:06 -0000 Received: (qmail 19095 invoked by uid 22791); 29 Oct 2010 15:10:04 -0000 X-SWARE-Spam-Status: No, hits=-1.9 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; Fri, 29 Oct 2010 15:09:56 +0000 Received: from [192.168.0.4] (79.36.29.49) by vsmtp14.tin.it (8.5.113) id 4BCE30370F306A5D; Fri, 29 Oct 2010 17:09:53 +0200 Message-ID: <4CCAE3C0.3070106@oracle.com> Date: Fri, 29 Oct 2010 17:09:52 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.14) Gecko/20101013 SUSE/3.0.9 Thunderbird/3.0.9 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: Re: [v3] First bits of libstdc++/44436 References: <4CC9A0CD.5000600@oracle.com> In-Reply-To: <4CC9A0CD.5000600@oracle.com> 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 On 10/28/2010 06:11 PM, Paolo Carlini wrote: > However, I'd like to ask your help (I'm addressing in particular the > library people of course) in figuring out a long term solution for the > _Select1st function object: the one we traditionally use in C++03 mode > doesn't work with move-semantics, because insists on using > container::value_type (the -2 testcases would not compile with it). For > the associative containers I guess the situation will be completely > similar and I'd like to figure out a satisfactory solution looking > forward, possibly improving the std::_Select1st itself and just using it > everywhere. Is __detail::_Select1st already ok for C++0x mode or we want > something better? > About this issue, I'm committing the below, a definite improvement, IMHO. With it, the associative containers should also be ok. Tested x86_64-linux Paolo. ///////////////////////////// 2010-10-29 Paolo Carlini * include/bits/stl_function.h (_Select1st<>::operator()): Add templatized overloads. * include/bits/hashtable_policy.h (_Select1st): Remove; revert everything to std::_Select1st. * include/bits/unordered_map.h: Likewise. Index: include/bits/hashtable_policy.h =================================================================== --- include/bits/hashtable_policy.h (revision 166059) +++ include/bits/hashtable_policy.h (working copy) @@ -56,14 +56,6 @@ return __distance_fw(__first, __last, _Tag()); } - struct _Select1st - { - template - const typename _Pair::first_type& - operator()(const _Pair& __pair) const - { return __pair.first; } - }; - // Auxiliary types used for all instantiations of _Hashtable: nodes // and iterators. @@ -511,13 +503,13 @@ struct _Map_base { }; template - struct _Map_base<_Key, _Pair, _Select1st, false, _Hashtable> + struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, false, _Hashtable> { typedef typename _Pair::second_type mapped_type; }; template - struct _Map_base<_Key, _Pair, _Select1st, true, _Hashtable> + struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable> { typedef typename _Pair::second_type mapped_type; @@ -537,9 +529,9 @@ }; template - typename _Map_base<_Key, _Pair, _Select1st, + typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& - _Map_base<_Key, _Pair, _Select1st, true, _Hashtable>:: + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: operator[](const _Key& __k) { _Hashtable* __h = static_cast<_Hashtable*>(this); @@ -556,9 +548,9 @@ } template - typename _Map_base<_Key, _Pair, _Select1st, + typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& - _Map_base<_Key, _Pair, _Select1st, true, _Hashtable>:: + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: operator[](_Key&& __k) { _Hashtable* __h = static_cast<_Hashtable*>(this); @@ -576,10 +568,10 @@ } template - typename _Map_base<_Key, _Pair, _Select1st, + typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& - _Map_base<_Key, _Pair, _Select1st, true, _Hashtable>:: - at(const _Key& __k) + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: + at(const _Key& __k) { _Hashtable* __h = static_cast<_Hashtable*>(this); typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); @@ -594,10 +586,10 @@ } template - const typename _Map_base<_Key, _Pair, _Select1st, + const typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& - _Map_base<_Key, _Pair, _Select1st, true, _Hashtable>:: - at(const _Key& __k) const + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: + at(const _Key& __k) const { const _Hashtable* __h = static_cast(this); typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); Index: include/bits/unordered_map.h =================================================================== --- include/bits/unordered_map.h (revision 166059) +++ include/bits/unordered_map.h (working copy) @@ -41,14 +41,14 @@ bool __cache_hash_code = false> class __unordered_map : public _Hashtable<_Key, std::pair, _Alloc, - __detail::_Select1st, _Pred, + std::_Select1st >, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, __cache_hash_code, false, true> { typedef _Hashtable<_Key, std::pair, _Alloc, - __detail::_Select1st, _Pred, + std::_Select1st >, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, @@ -69,7 +69,7 @@ const allocator_type& __a = allocator_type()) : _Base(__n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } template @@ -80,7 +80,7 @@ const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } __unordered_map(initializer_list __l, @@ -91,7 +91,7 @@ : _Base(__l.begin(), __l.end(), __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } __unordered_map& @@ -111,7 +111,7 @@ class __unordered_multimap : public _Hashtable<_Key, std::pair, _Alloc, - __detail::_Select1st, _Pred, + std::_Select1st >, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, @@ -119,7 +119,7 @@ { typedef _Hashtable<_Key, std::pair, _Alloc, - __detail::_Select1st, _Pred, + std::_Select1st >, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, @@ -140,7 +140,7 @@ const allocator_type& __a = allocator_type()) : _Base(__n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } @@ -152,7 +152,7 @@ const allocator_type& __a = allocator_type()) : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } __unordered_multimap(initializer_list __l, @@ -163,7 +163,7 @@ : _Base(__l.begin(), __l.end(), __n, __hf, __detail::_Mod_range_hashing(), __detail::_Default_ranged_hash(), - __eql, __detail::_Select1st(), __a) + __eql, std::_Select1st >(), __a) { } __unordered_multimap& Index: include/bits/stl_function.h =================================================================== --- include/bits/stl_function.h (revision 166059) +++ include/bits/stl_function.h (working copy) @@ -487,6 +487,18 @@ const typename _Pair::first_type& operator()(const _Pair& __x) const { return __x.first; } + +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + template + typename _Pair2::first_type& + operator()(_Pair2& __x) const + { return __x.first; } + + template + const typename _Pair2::first_type& + operator()(const _Pair2& __x) const + { return __x.first; } +#endif }; template