Patchwork [v3] First bits of libstdc++/44436

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 29, 2010, 3:09 p.m.
Message ID <4CCAE3C0.3070106@oracle.com>
Download mbox | patch
Permalink /patch/69602/
State New
Headers show

Comments

Paolo Carlini - Oct. 29, 2010, 3:09 p.m.
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  <paolo.carlini@oracle.com>

	* 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.

Patch

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<typename _Pair>
-      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<typename _Key, typename _Pair, typename _Hashtable>
-    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<typename _Key, typename _Pair, typename _Hashtable>
-    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 _Key, typename _Pair, typename _Hashtable>
-    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 _Key, typename _Pair, typename _Hashtable>
-    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 _Key, typename _Pair, typename _Hashtable>
-    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<typename _Key, typename _Pair, typename _Hashtable>
-    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<const _Hashtable*>(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<const _Key, _Tp>, _Alloc,
-			__detail::_Select1st, _Pred, 
+			std::_Select1st<std::pair<const _Key, _Tp> >, _Pred, 
 			_Hash, __detail::_Mod_range_hashing,
 			__detail::_Default_ranged_hash,
 			__detail::_Prime_rehash_policy,
 			__cache_hash_code, false, true>
     {
       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>, _Alloc,
-			 __detail::_Select1st, _Pred,
+			 std::_Select1st<std::pair<const _Key, _Tp> >, _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<std::pair<const _Key, _Tp> >(), __a)
       { }
 
       template<typename _InputIterator>
@@ -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<std::pair<const _Key, _Tp> >(), __a)
 	{ }
 
       __unordered_map(initializer_list<value_type> __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<std::pair<const _Key, _Tp> >(), __a)
       { }
 
       __unordered_map&
@@ -111,7 +111,7 @@ 
     class __unordered_multimap
     : public _Hashtable<_Key, std::pair<const _Key, _Tp>,
 			_Alloc,
-			__detail::_Select1st, _Pred,
+			std::_Select1st<std::pair<const _Key, _Tp> >, _Pred,
 			_Hash, __detail::_Mod_range_hashing,
 			__detail::_Default_ranged_hash,
 			__detail::_Prime_rehash_policy,
@@ -119,7 +119,7 @@ 
     {
       typedef _Hashtable<_Key, std::pair<const _Key, _Tp>,
 			 _Alloc,
-			 __detail::_Select1st, _Pred,
+			 std::_Select1st<std::pair<const _Key, _Tp> >, _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<std::pair<const _Key, _Tp> >(), __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<std::pair<const _Key, _Tp> >(), __a)
         { }
 
       __unordered_multimap(initializer_list<value_type> __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<std::pair<const _Key, _Tp> >(), __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>
+        typename _Pair2::first_type&
+        operator()(_Pair2& __x) const
+        { return __x.first; }
+
+      template<typename _Pair2>
+        const typename _Pair2::first_type&
+        operator()(const _Pair2& __x) const
+        { return __x.first; }
+#endif
     };
 
   template<typename _Pair>