try_emplace and insert_or_assign for Debug Mode.
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Aug 2015 20:58:14 +0000 (21:58 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 26 Aug 2015 20:58:14 +0000 (21:58 +0100)
* include/debug/map.h (map::try_emplace, map::insert_or_assign):
Define.
* include/debug/unordered_map (unordered_map::try_emplace,
unordered_map::insert_or_assign): Define.

From-SVN: r227229

libstdc++-v3/ChangeLog
libstdc++-v3/include/debug/map.h
libstdc++-v3/include/debug/unordered_map

index 1422cc46b3f350b47a7c1c90da80b581103c3d48..0bc0aca0211dc873559c46d66fb4974099790e64 100644 (file)
@@ -1,5 +1,10 @@
 2015-08-26  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/debug/map.h (map::try_emplace, map::insert_or_assign):
+       Define.
+       * include/debug/unordered_map (unordered_map::try_emplace,
+       unordered_map::insert_or_assign): Define.
+
        PR libstdc++/66902
        * src/c++11/debug.cc (_S_debug_messages): Give internal linkage.
 
index d45cf793e9d033806d17224e4781dd0d83335344..914d72150376c6f687a70121a456829a23203520 100644 (file)
@@ -317,6 +317,89 @@ namespace __debug
            _Base::insert(__first, __last);
        }
 
+
+#if __cplusplus > 201402L
+      template <typename... _Args>
+        pair<iterator, bool>
+        try_emplace(const key_type& __k, _Args&&... __args)
+        {
+         auto __res = _Base::try_emplace(__k,
+                                         std::forward<_Args>(__args)...);
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename... _Args>
+        pair<iterator, bool>
+        try_emplace(key_type&& __k, _Args&&... __args)
+        {
+         auto __res = _Base::try_emplace(std::move(__k),
+                                         std::forward<_Args>(__args)...);
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename... _Args>
+        iterator
+        try_emplace(const_iterator __hint, const key_type& __k,
+                    _Args&&... __args)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::try_emplace(__hint.base(), __k,
+                                            std::forward<_Args>(__args)...),
+                         this);
+       }
+
+      template <typename... _Args>
+        iterator
+        try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::try_emplace(__hint.base(), std::move(__k),
+                                            std::forward<_Args>(__args)...),
+                         this);
+       }
+
+      template <typename _Obj>
+        std::pair<iterator, bool>
+        insert_or_assign(const key_type& __k, _Obj&& __obj)
+       {
+         auto __res = _Base::insert_or_assign(__k,
+                                              std::forward<_Obj>(__obj));
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename _Obj>
+        std::pair<iterator, bool>
+        insert_or_assign(key_type&& __k, _Obj&& __obj)
+       {
+         auto __res = _Base::insert_or_assign(std::move(__k),
+                                              std::forward<_Obj>(__obj));
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename _Obj>
+        iterator
+        insert_or_assign(const_iterator __hint,
+                         const key_type& __k, _Obj&& __obj)
+       {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::insert_or_assign(__hint.base(), __k,
+                                                 std::forward<_Obj>(__obj)),
+                         this);
+       }
+
+      template <typename _Obj>
+        iterator
+        insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::insert_or_assign(__hint.base(),
+                                                 std::move(__k),
+                                                 std::forward<_Obj>(__obj)),
+                         this);
+       }
+#endif
+
+
 #if __cplusplus >= 201103L
       iterator
       erase(const_iterator __position)
index cc3bc3fb7bcbc487d2216b153b90c65628a3a7ce..1bbdb614af3e35792427f09e31f16befb336488c 100644 (file)
@@ -377,6 +377,88 @@ namespace __debug
          _M_check_rehashed(__bucket_count);
        }
 
+#if __cplusplus > 201402L
+      template <typename... _Args>
+        pair<iterator, bool>
+        try_emplace(const key_type& __k, _Args&&... __args)
+        {
+         auto __res = _Base::try_emplace(__k,
+                                         std::forward<_Args>(__args)...);
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename... _Args>
+        pair<iterator, bool>
+        try_emplace(key_type&& __k, _Args&&... __args)
+        {
+         auto __res = _Base::try_emplace(std::move(__k),
+                                         std::forward<_Args>(__args)...);
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename... _Args>
+        iterator
+        try_emplace(const_iterator __hint, const key_type& __k,
+                    _Args&&... __args)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::try_emplace(__hint.base(), __k,
+                                            std::forward<_Args>(__args)...),
+                         this);
+       }
+
+      template <typename... _Args>
+        iterator
+        try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::try_emplace(__hint.base(), std::move(__k),
+                                            std::forward<_Args>(__args)...),
+                         this);
+       }
+
+      template <typename _Obj>
+        pair<iterator, bool>
+        insert_or_assign(const key_type& __k, _Obj&& __obj)
+        {
+         auto __res = _Base::insert_or_assign(__k,
+                                              std::forward<_Obj>(__obj));
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename _Obj>
+        pair<iterator, bool>
+        insert_or_assign(key_type&& __k, _Obj&& __obj)
+        {
+         auto __res = _Base::insert_or_assign(std::move(__k),
+                                              std::forward<_Obj>(__obj));
+         return { iterator(__res.first, this), __res.second };
+       }
+
+      template <typename _Obj>
+        iterator
+        insert_or_assign(const_iterator __hint, const key_type& __k,
+                         _Obj&& __obj)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::insert_or_assign(__hint.base(), __k,
+                                                 std::forward<_Obj>(__obj)),
+                         this);
+       }
+
+      template <typename _Obj>
+        iterator
+        insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
+        {
+         __glibcxx_check_insert(__hint);
+         return iterator(_Base::insert_or_assign(__hint.base(),
+                                                 std::move(__k),
+                                                 std::forward<_Obj>(__obj)),
+                         this);
+       }
+#endif
+
+
       iterator
       find(const key_type& __key)
       { return iterator(_Base::find(__key), this); }