diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /include/map | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) | |
download | src-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.tar.gz src-61b9a7258a7693d7f3674a5a1daf7b036ff1d382.zip |
Import libc++ 3.7.0 release (r246257).vendor/libc++/libc++-release_370-r246257
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=287518
svn path=/vendor/libc++/libc++-release_370-r246257/; revision=287519; tag=vendor/libc++/libc++-release_370-r246257
Diffstat (limited to 'include/map')
-rw-r--r-- | include/map | 231 |
1 files changed, 193 insertions, 38 deletions
diff --git a/include/map b/include/map index 5c3969acdd28..eb6b8ed05308 100644 --- a/include/map +++ b/include/map @@ -135,16 +135,32 @@ public: void insert(InputIterator first, InputIterator last); void insert(initializer_list<value_type> il); + 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; void swap(map& m) - noexcept( - __is_nothrow_swappable<key_compare>::value && - (!allocator_type::propagate_on_container_swap::value || - __is_nothrow_swappable<allocator_type>::value)); + noexcept(allocator_traits<allocator_type>::is_always_equal::value && + __is_nothrow_swappable<key_compare>::value); // C++17 // observers: allocator_type get_allocator() const noexcept; @@ -330,15 +346,14 @@ public: void insert(initializer_list<value_type> il); 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; void swap(multimap& m) - noexcept( - __is_nothrow_swappable<key_compare>::value && - (!allocator_type::propagate_on_container_swap::value || - __is_nothrow_swappable<allocator_type>::value)); + noexcept(allocator_traits<allocator_type>::is_always_equal::value && + __is_nothrow_swappable<key_compare>::value); // C++17 // observers: allocator_type get_allocator() const noexcept; @@ -426,6 +441,7 @@ swap(multimap<Key, T, Compare, Allocator>& x, #include <utility> #include <functional> #include <initializer_list> +#include <type_traits> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -433,10 +449,8 @@ swap(multimap<Key, T, Compare, Allocator>& x, _LIBCPP_BEGIN_NAMESPACE_STD -template <class _Key, class _CP, class _Compare, bool = is_empty<_Compare>::value -#if __has_feature(is_final) - && !__is_final(_Compare) -#endif +template <class _Key, class _CP, class _Compare, + bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value > class __map_value_compare : private _Compare @@ -461,6 +475,12 @@ public: _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const {return static_cast<const _Compare&>(*this)(__x, __y.__cc.first);} + void swap(__map_value_compare&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) + { + using _VSTD::swap; + swap(static_cast<const _Compare&>(*this), static_cast<const _Compare&>(__y)); + } #if _LIBCPP_STD_VER > 11 template <typename _K2> @@ -503,7 +523,13 @@ public: _LIBCPP_INLINE_VISIBILITY bool operator()(const _Key& __x, const _CP& __y) const {return comp(__x, __y.__cc.first);} - + void swap(__map_value_compare&__y) + _NOEXCEPT_(__is_nothrow_swappable<_Compare>::value) + { + using _VSTD::swap; + swap(comp, __y.comp); + } + #if _LIBCPP_STD_VER > 11 template <typename _K2> _LIBCPP_INLINE_VISIBILITY @@ -519,6 +545,16 @@ public: #endif }; +template <class _Key, class _CP, class _Compare, bool __b> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x, + __map_value_compare<_Key, _CP, _Compare, __b>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + template <class _Allocator> class __map_node_destructor { @@ -644,14 +680,25 @@ struct __value_type #endif +template <class _Tp> +struct __extract_key_value_types; + +template <class _Key, class _Tp> +struct __extract_key_value_types<__value_type<_Key, _Tp> > +{ + typedef _Key const __key_type; + typedef _Tp __mapped_type; +}; + template <class _TreeIterator> class _LIBCPP_TYPE_VIS_ONLY __map_iterator { _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; + typedef typename _TreeIterator::value_type __value_type; + typedef typename __extract_key_value_types<__value_type>::__key_type __key_type; + typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -715,8 +762,9 @@ class _LIBCPP_TYPE_VIS_ONLY __map_const_iterator _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; + typedef typename _TreeIterator::value_type __value_type; + typedef typename __extract_key_value_types<__value_type>::__key_type __key_type; + typedef typename __extract_key_value_types<__value_type>::__mapped_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -736,10 +784,9 @@ public: _LIBCPP_INLINE_VISIBILITY __map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY - __map_const_iterator( - __map_iterator<typename _TreeIterator::__non_const_iterator> __i) - _NOEXCEPT - : __i_(__i.__i_) {} + __map_const_iterator(__map_iterator< + typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT + : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __i_->__cc;} @@ -811,13 +858,8 @@ private: typedef _VSTD::__value_type<key_type, mapped_type> __value_type; typedef __map_value_compare<key_type, __value_type, key_compare> __vc; - 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 __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits<allocator_type> __alloc_traits; @@ -829,7 +871,7 @@ public: typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; - typedef __map_iterator<typename __base::iterator> iterator; + typedef __map_iterator<typename __base::iterator> iterator; typedef __map_const_iterator<typename __base::const_iterator> const_iterator; typedef _VSTD::reverse_iterator<iterator> reverse_iterator; typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; @@ -1070,9 +1112,125 @@ public: #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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + 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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + 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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + return __p; + else + return emplace_hint(__p, + _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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + return __p; + else + return emplace_hint(__p, + _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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return _VSTD::make_pair(__p, false); + } + return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__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 = lower_bound(__k); + if ( __p != end() && !key_comp()(__k, __p->first)) + { + __p->second = _VSTD::forward<_Vp>(__v); + return __p; + } + return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)); + } +#endif +#endif +#endif + _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __tree_.__erase_unique(__k);} _LIBCPP_INLINE_VISIBILITY @@ -1108,7 +1266,7 @@ public: template <typename _K2> _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type - count(const _K2& __k) {return __tree_.__count_unique(__k);} + count(const _K2& __k) const {return __tree_.__count_unique(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) @@ -1557,13 +1715,8 @@ private: typedef _VSTD::__value_type<key_type, mapped_type> __value_type; typedef __map_value_compare<key_type, __value_type, key_compare> __vc; - 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 __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits<allocator_type> __alloc_traits; @@ -1810,6 +1963,8 @@ public: _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);} _LIBCPP_INLINE_VISIBILITY + iterator erase(iterator __p) {return __tree_.erase(__p.__i_);} + _LIBCPP_INLINE_VISIBILITY size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);} _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __f, const_iterator __l) @@ -1844,7 +1999,7 @@ public: template <typename _K2> _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type - count(const _K2& __k) {return __tree_.__count_multi(__k);} + count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) |