diff mbox

[v3] Don't declare insert(&&) members in _Hashtable

Message ID 4E89D594.8070508@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 3, 2011, 3:32 p.m. UTC
Hi,

noticed while working on finally defaulting pair' move constructor (the 
way to go, proposed by Daniel, seems to be using 
std::is_constructible<value_type, P&&> instead of std::is_convertible 
for constraining. Testing that uncovered a number of interesting latent 
issues at various levels ;)

Tested x86_64-linux, committed.

Paolo.

/////////////////////////
2011-10-03  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/hashtable.h (_Hashtable<>::insert(value_type&&),
	insert(const_iterator, value_type&&)): Don't define here...
	* include/bits/unordered_set.h (__unordered_set<>,
	__unordered_multiset<>): ... define here instead.
diff mbox

Patch

Index: include/bits/hashtable.h
===================================================================
--- include/bits/hashtable.h	(revision 179456)
+++ include/bits/hashtable.h	(working copy)
@@ -374,14 +374,6 @@ 
 	_M_insert_bucket(_Arg&&, size_type,
 			 typename _Hashtable::_Hash_code_type);
 
-      template<typename _Arg>
-	std::pair<iterator, bool>
-	_M_insert(_Arg&&, std::true_type);
-
-      template<typename _Arg>
-	iterator
-	_M_insert(_Arg&&, std::false_type);
-
       typedef typename std::conditional<__unique_keys,
 					std::pair<iterator, bool>,
 					iterator>::type
@@ -393,38 +385,38 @@ 
 				   >::type
 	_Insert_Conv_Type;
 
+    protected:
+      template<typename _Arg>
+	std::pair<iterator, bool>
+	_M_insert(_Arg&&, std::true_type);
+
+      template<typename _Arg>
+	iterator
+	_M_insert(_Arg&&, std::false_type);
+
     public:
       // Insert and erase
       _Insert_Return_Type
       insert(const value_type& __v)
-      { return _M_insert(__v, std::integral_constant<bool, __unique_keys>()); }
+      { return _M_insert(__v, integral_constant<bool, __unique_keys>()); }
 
       iterator
       insert(const_iterator, const value_type& __v)
       { return _Insert_Conv_Type()(insert(__v)); }
 
-      _Insert_Return_Type
-      insert(value_type&& __v)
-      { return _M_insert(std::move(__v),
-			 std::integral_constant<bool, __unique_keys>()); }
-
-      iterator
-      insert(const_iterator, value_type&& __v)
-      { return _Insert_Conv_Type()(insert(std::move(__v))); }
-
       template<typename _Pair, typename = typename
-	       std::enable_if<!__constant_iterators
-			      && std::is_convertible<_Pair,
-						     value_type>::value>::type>
+	std::enable_if<__and_<integral_constant<bool, !__constant_iterators>,
+			      std::is_convertible<_Pair,
+						  value_type>>::value>::type>
 	_Insert_Return_Type
 	insert(_Pair&& __v)
 	{ return _M_insert(std::forward<_Pair>(__v),
-			   std::integral_constant<bool, __unique_keys>()); }
+			   integral_constant<bool, __unique_keys>()); }
 
       template<typename _Pair, typename = typename
-	       std::enable_if<!__constant_iterators
-			      && std::is_convertible<_Pair,
-						     value_type>::value>::type>
+        std::enable_if<__and_<integral_constant<bool, !__constant_iterators>,
+			      std::is_convertible<_Pair,
+						  value_type>>::value>::type>
 	iterator
 	insert(const_iterator, _Pair&& __v)
 	{ return _Insert_Conv_Type()(insert(std::forward<_Pair>(__v))); }
Index: include/bits/unordered_set.h
===================================================================
--- include/bits/unordered_set.h	(revision 179456)
+++ include/bits/unordered_set.h	(working copy)
@@ -63,7 +63,9 @@ 
       typedef typename _Base::hasher          hasher;
       typedef typename _Base::key_equal       key_equal;
       typedef typename _Base::allocator_type  allocator_type;
-      
+      typedef typename _Base::iterator        iterator;
+      typedef typename _Base::const_iterator  const_iterator;
+
       explicit
       __unordered_set(size_type __n = 10,
 		      const hasher& __hf = hasher(),
@@ -103,6 +105,16 @@ 
 	this->insert(__l.begin(), __l.end());
 	return *this;
       }
+
+      using _Base::insert;
+
+      std::pair<iterator, bool>
+      insert(value_type&& __v)
+      { return this->_M_insert(std::move(__v), std::true_type()); }
+
+      iterator
+      insert(const_iterator, value_type&& __v)
+      { return insert(std::move(__v)).first; }
     };
 
   template<class _Value,
@@ -132,7 +144,9 @@ 
       typedef typename _Base::hasher          hasher;
       typedef typename _Base::key_equal       key_equal;
       typedef typename _Base::allocator_type  allocator_type;
-      
+      typedef typename _Base::iterator        iterator;
+      typedef typename _Base::const_iterator  const_iterator;
+
       explicit
       __unordered_multiset(size_type __n = 10,
 			   const hasher& __hf = hasher(),
@@ -173,6 +187,16 @@ 
 	this->insert(__l.begin(), __l.end());
 	return *this;
       }
+
+      using _Base::insert;
+
+      iterator
+      insert(value_type&& __v)
+      { return this->_M_insert(std::move(__v), std::false_type()); }
+
+      iterator
+      insert(const_iterator, value_type&& __v)
+      { return insert(std::move(__v)); }
     };
 
   template<class _Value, class _Hash, class _Pred, class _Alloc,