diff options
Diffstat (limited to 'include/unordered_map')
-rw-r--r-- | include/unordered_map | 215 |
1 files changed, 191 insertions, 24 deletions
diff --git a/include/unordered_map b/include/unordered_map index 0fa87d19ad035..cf70ab62f69ed 100644 --- a/include/unordered_map +++ b/include/unordered_map @@ -122,7 +122,25 @@ public: void insert(InputIterator first, InputIterator last); void insert(initializer_list<value_type>); + template <class... Args> + pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 + template <class... Args> + pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 + template <class... Args> + iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 + template <class M> + pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 + template <class M> + iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 + iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 size_type erase(const key_type& k); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; @@ -287,6 +305,7 @@ public: void insert(initializer_list<value_type>); iterator erase(const_iterator position); + iterator erase(iterator position); // C++14 size_type erase(const key_type& k); iterator erase(const_iterator first, const_iterator last); void clear() noexcept; @@ -359,10 +378,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc> _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _Cp, class _Hash, bool = is_empty<_Hash>::value -#if __has_feature(is_final) - && !__is_final(_Hash) -#endif +template <class _Key, class _Cp, class _Hash, + bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value > class __unordered_map_hasher : private _Hash @@ -384,6 +401,12 @@ public: _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Key& __x) const {return static_cast<const _Hash&>(*this)(__x);} + void swap(__unordered_map_hasher&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) + { + using _VSTD::swap; + swap(static_cast<const _Hash&>(*this), static_cast<const _Hash&>(__y)); + } }; template <class _Key, class _Cp, class _Hash> @@ -408,12 +431,26 @@ public: _LIBCPP_INLINE_VISIBILITY size_t operator()(const _Key& __x) const {return __hash_(__x);} + void swap(__unordered_map_hasher&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Hash>::value) + { + using _VSTD::swap; + swap(__hash_, __y.__hash_); + } }; -template <class _Key, class _Cp, class _Pred, bool = is_empty<_Pred>::value -#if __has_feature(is_final) - && !__is_final(_Pred) -#endif +template <class _Key, class _Cp, class _Hash, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x, + __unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +template <class _Key, class _Cp, class _Pred, + bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value > class __unordered_map_equal : private _Pred @@ -438,6 +475,12 @@ public: _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _Cp& __y) const {return static_cast<const _Pred&>(*this)(__x, __y.__cc.first);} + void swap(__unordered_map_equal&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) + { + using _VSTD::swap; + swap(static_cast<const _Pred&>(*this), static_cast<const _Pred&>(__y)); + } }; template <class _Key, class _Cp, class _Pred> @@ -465,8 +508,24 @@ public: _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _Cp& __y) const {return __pred_(__x, __y.__cc.first);} + void swap(__unordered_map_equal&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Pred>::value) + { + using _VSTD::swap; + swap(__pred_, __y.__pred_); + } }; +template <class _Key, class _Cp, class _Pred, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x, + __unordered_map_equal<_Key, _Cp, _Pred, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + template <class _Alloc> class __hash_map_node_destructor { @@ -551,7 +610,7 @@ union __hash_value_type _LIBCPP_INLINE_VISIBILITY __hash_value_type(__hash_value_type&& __v) - : __nc(std::move(__v.__nc)) {} + : __nc(_VSTD::move(__v.__nc)) {} _LIBCPP_INLINE_VISIBILITY __hash_value_type& operator=(const __hash_value_type& __v) @@ -559,7 +618,7 @@ union __hash_value_type _LIBCPP_INLINE_VISIBILITY __hash_value_type& operator=(__hash_value_type&& __v) - {__nc = std::move(__v.__nc); return *this;} + {__nc = _VSTD::move(__v.__nc); return *this;} _LIBCPP_INLINE_VISIBILITY ~__hash_value_type() {__cc.~value_type();} @@ -730,13 +789,8 @@ private: typedef __hash_value_type<key_type, mapped_type> __value_type; typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; - typedef typename allocator_traits<allocator_type>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -946,9 +1000,125 @@ public: {insert(__il.begin(), __il.end());} #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if _LIBCPP_STD_VER > 14 +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + return _VSTD::make_pair(__p, false); + else + return _VSTD::make_pair( + emplace_hint(__p, + _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)), + true); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + return _VSTD::make_pair(__p, false); + else + return _VSTD::make_pair( + emplace_hint(__p, + _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)), + true); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + return __p; + else + return emplace_hint(__h, + _VSTD::piecewise_construct, _VSTD::forward_as_tuple(__k), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + return __p; + else + return emplace_hint(__h, + _VSTD::piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__k)), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + { + __p->second = _VSTD::move(__v); + return _VSTD::make_pair(__p, false); + } + return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + { + __p->second = _VSTD::move(__v); + return _VSTD::make_pair(__p, false); + } + return _VSTD::make_pair(emplace_hint(__p, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)), true); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + { + __p->second = _VSTD::move(__v); + return __p; + } + return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v) + { + iterator __p = __table_.find(__k); + if ( __p != end()) + { + __p->second = _VSTD::move(__v); + return __p; + } + return emplace_hint(__h, _VSTD::forward<key_type>(__k), _VSTD::forward<_Vp>(__v)); + } +#endif +#endif +#endif + _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);} _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __first, const_iterator __last) @@ -1469,13 +1639,8 @@ private: typedef __hash_value_type<key_type, mapped_type> __value_type; typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher; typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal; - typedef typename allocator_traits<allocator_type>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, + __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -1654,6 +1819,8 @@ public: _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __table_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);} _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __first, const_iterator __last) |