OSDN Git Service

2010-11-10 François Dumont <francois.cppdevs@free.fr>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / profile / unordered_map
index b90d58b..6d6a8b7 100644 (file)
 #ifndef _GLIBCXX_PROFILE_UNORDERED_MAP
 #define _GLIBCXX_PROFILE_UNORDERED_MAP 1
 
-#include <profile/base.h>
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-# include <unordered_map>
-#else
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
 # include <bits/c++0x_warning.h>
-#endif
+#else
+# include <unordered_map>
 
-#include <initializer_list>
+#include <profile/base.h>
 
 #define _GLIBCXX_BASE unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>
 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_PR::_GLIBCXX_BASE
@@ -89,10 +86,10 @@ namespace __profile
 
       template<typename _InputIterator>
         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());
@@ -107,14 +104,14 @@ namespace __profile
       }
 
       unordered_map(unordered_map&& __x)
-      : _Base(std::forward<_Base>(__x)) 
+      : _Base(std::move(__x)) 
       {
         __profcxx_hashtable_construct(this, _Base::bucket_count());
         __profcxx_hashtable_construct2(this);
       }
 
       unordered_map(initializer_list<value_type> __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())
@@ -173,7 +170,7 @@ namespace __profile
       { 
         size_type __old_size = _Base::bucket_count(); 
         _Base::insert(__l);
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        _M_profile_resize(__old_size); 
       }
 
       std::pair<iterator, bool>
@@ -181,7 +178,7 @@ namespace __profile
       {
         size_type __old_size =  _Base::bucket_count();
         std::pair<iterator, bool> __res = _Base::insert(__obj);
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        _M_profile_resize(__old_size); 
         return __res;
       }
 
@@ -190,17 +187,42 @@ namespace __profile
       { 
         size_type __old_size = _Base::bucket_count(); 
         iterator __res = _Base::insert(__iter, __v);
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        _M_profile_resize(__old_size); 
         return __res;
       }
 
+      template<typename _Pair, typename = typename
+              std::enable_if<std::is_convertible<_Pair,
+                                                 value_type>::value>::type>
+        std::pair<iterator, bool>
+        insert(_Pair&& __obj)
+        {
+         size_type __old_size =  _Base::bucket_count();
+         std::pair<iterator, bool> __res
+           = _Base::insert(std::forward<_Pair>(__obj));
+         _M_profile_resize(__old_size); 
+         return __res;
+       }
+
+      template<typename _Pair, typename = typename
+              std::enable_if<std::is_convertible<_Pair,
+                                                 value_type>::value>::type>
+        iterator
+        insert(const_iterator __iter, _Pair&& __v)
+        { 
+         size_type __old_size = _Base::bucket_count(); 
+         iterator __res = _Base::insert(__iter, std::forward<_Pair>(__v));
+         _M_profile_resize(__old_size); 
+         return __res;
+       }
+
       template<typename _InputIter>
         void
         insert(_InputIter __first, _InputIter __last)
         {
          size_type __old_size = _Base::bucket_count(); 
-         _Base::insert(__first.base(), __last.base());
-         _M_profile_resize(__old_size, _Base::bucket_count()); 
+         _Base::insert(__first, __last);
+         _M_profile_resize(__old_size); 
        }
 
       void
@@ -208,19 +230,27 @@ namespace __profile
       {
         size_type __old_size = _Base::bucket_count(); 
         _Base::insert(__first, __last);
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        _M_profile_resize(__old_size); 
       }
-     
-      // operator []
+
+      // operator[]
       mapped_type&
-      operator[](const _Key& _k)
+      operator[](const _Key& __k)
       {
         size_type __old_size =  _Base::bucket_count();
-        mapped_type& __res = _M_base()[_k];
-        size_type __new_size =  _Base::bucket_count();
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        mapped_type& __res = _M_base()[__k];
+        _M_profile_resize(__old_size); 
         return __res;
-      }   
+      }
+
+      mapped_type&
+      operator[](_Key&& __k)
+      {
+        size_type __old_size =  _Base::bucket_count();
+        mapped_type& __res = _M_base()[std::move(__k)];
+        _M_profile_resize(__old_size); 
+        return __res;
+      }
 
       void
       swap(unordered_map& __x)
@@ -230,13 +260,14 @@ namespace __profile
       {
         size_type __old_size =  _Base::bucket_count();
         _Base::rehash(__n);
-        _M_profile_resize(__old_size, _Base::bucket_count()); 
+        _M_profile_resize(__old_size); 
       }
 
     private:
       void
-      _M_profile_resize(size_type __old_size, size_type __new_size)
+      _M_profile_resize(size_type __old_size)
       {
+       size_type __new_size = _Base::bucket_count();
         if (__old_size != __new_size)
          __profcxx_hashtable_resize(this, __old_size, __new_size);
       }
@@ -272,6 +303,20 @@ namespace __profile
         unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
     { __x.swap(__y); }
 
+  template<typename _Key, typename _Tp, typename _Hash,
+          typename _Pred, typename _Alloc>
+    inline bool
+    operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+              const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+    { return __x._M_equal(__y); }
+
+  template<typename _Key, typename _Tp, typename _Hash,
+          typename _Pred, typename _Alloc>
+    inline bool
+    operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+              const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+    { return !(__x == __y); }
+
 #undef _GLIBCXX_BASE
 #undef _GLIBCXX_STD_BASE
 #define _GLIBCXX_BASE unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>
@@ -303,19 +348,19 @@ namespace __profile
 
       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<typename _InputIterator>
         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());
@@ -328,13 +373,13 @@ namespace __profile
       }
 
       unordered_multimap(unordered_multimap&& __x)
-      : _Base(std::forward<_Base>(__x))
+      : _Base(std::move(__x))
       {
         __profcxx_hashtable_construct(this, _Base::bucket_count());
       }
 
       unordered_multimap(initializer_list<value_type> __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())
@@ -409,17 +454,41 @@ namespace __profile
       insert(const_iterator __iter, const value_type& __v)
       { 
         size_type __old_size = _Base::bucket_count(); 
-        iterator __res =_Base::insert(__iter, __v);
+        iterator __res = _Base::insert(__iter, __v);
         _M_profile_resize(__old_size, _Base::bucket_count()); 
         return __res;
       }
 
+      template<typename _Pair, typename = typename
+              std::enable_if<std::is_convertible<_Pair,
+                                                 value_type>::value>::type>
+        iterator
+        insert(_Pair&& __obj)
+        {
+         size_type __old_size =  _Base::bucket_count();
+         iterator __res = _Base::insert(std::forward<_Pair>(__obj));
+         _M_profile_resize(__old_size, _Base::bucket_count()); 
+         return __res;
+       }
+
+      template<typename _Pair, typename = typename
+              std::enable_if<std::is_convertible<_Pair,
+                                                 value_type>::value>::type>
+        iterator
+        insert(const_iterator __iter, _Pair&& __v)
+        {
+         size_type __old_size = _Base::bucket_count(); 
+         iterator __res = _Base::insert(__iter, std::forward<_Pair>(__v));
+         _M_profile_resize(__old_size, _Base::bucket_count()); 
+         return __res;
+       }
+
       template<typename _InputIter>
         void
         insert(_InputIter __first, _InputIter __last)
         {
          size_type __old_size = _Base::bucket_count(); 
-         _Base::insert(__first.base(), __last.base());
+         _Base::insert(__first, __last);
          _M_profile_resize(__old_size, _Base::bucket_count()); 
        }
 
@@ -482,10 +551,26 @@ namespace __profile
         unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
     { __x.swap(__y); }
 
+  template<typename _Key, typename _Tp, typename _Hash,
+          typename _Pred, typename _Alloc>
+    inline bool
+    operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+              const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+    { return __x._M_equal(__y); }
+
+  template<typename _Key, typename _Tp, typename _Hash,
+          typename _Pred, typename _Alloc>
+    inline bool
+    operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
+              const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
+    { return !(__x == __y); }
+
 } // namespace __profile
 } // namespace std
 
 #undef _GLIBCXX_BASE
 #undef _GLIBCXX_STD_BASE
 
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
 #endif