From 66c182be120bb3777329475c67338b7c0d9ad2f4 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 26 Aug 2015 21:58:14 +0100 Subject: [PATCH] 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. From-SVN: r227229 --- libstdc++-v3/ChangeLog | 5 ++ libstdc++-v3/include/debug/map.h | 83 ++++++++++++++++++++++++ libstdc++-v3/include/debug/unordered_map | 82 +++++++++++++++++++++++ 3 files changed, 170 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1422cc46b3f..0bc0aca0211 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2015-08-26 Jonathan Wakely + * 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. diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h index d45cf793e9d..914d7215037 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 + pair + 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 + pair + 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 + 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 + 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 + std::pair + 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 + std::pair + 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 + 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 + 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 cc3bc3fb7bc..1bbdb614af3 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 + pair + 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 + pair + 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 + 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 + 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 + pair + 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 + pair + 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 + 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 + 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); } -- 2.30.2