This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3 patch] try_emplace and insert_or_assign for Debug Mode.


These new members need to be defined in Debug Mode, because the
iterators passed in as hints and returned as results need to be safe
iterators.

No new tests, because we already have tests for these members, and
they're failing in debug mode.

Tested powerpc64le-linux, committed to trunk.


commit ae899df9056ff8a58d658ef42125935856503f96
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Aug 26 21:24:30 2015 +0100

    try_emplace and insert_or_assign for Debug Mode.
    
    	* 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.

diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h
index d45cf79..914d721 100644
--- a/libstdc++-v3/include/debug/map.h
+++ b/libstdc++-v3/include/debug/map.h
@@ -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)
diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map
index cc3bc3f..1bbdb61 100644
--- a/libstdc++-v3/include/debug/unordered_map
+++ b/libstdc++-v3/include/debug/unordered_map
@@ -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); }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]