diff options
author | Howard Hinnant <hhinnant@apple.com> | 2012-05-25 22:04:21 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2012-05-25 22:04:21 +0000 |
commit | 8b805c915a3847e72b6bb028e9fb3af1b17349df (patch) | |
tree | eca09a65e87c1a27efd6e8acc9ec951dcfe2d3b4 /libcxx/include/map | |
parent | 7b29885463742ee73d2585d9d8fd8926d4222f73 (diff) | |
download | bcm5719-llvm-8b805c915a3847e72b6bb028e9fb3af1b17349df.tar.gz bcm5719-llvm-8b805c915a3847e72b6bb028e9fb3af1b17349df.zip |
The rules for emplace in map, multimap, unordered_map and unordered_multimap changed a while back and I'm just now updating to these new rules. In a nutshell, you've got to know you're emplacing to a pair and use one of pair's constructors. I made one extension: If you want to emplace the key and default construct the mapped_type, you can just emplace(key), as opposed to emplace(piecewise_construct, forward_as_tuple(key), forward_as_tuple()).
llvm-svn: 157503
Diffstat (limited to 'libcxx/include/map')
-rw-r--r-- | libcxx/include/map | 229 |
1 files changed, 109 insertions, 120 deletions
diff --git a/libcxx/include/map b/libcxx/include/map index 633579b7ee0..dd98da5e7ae 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -880,45 +880,15 @@ public: value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - - _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> - emplace() {return __tree_.__emplace_unique();} - - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> - emplace(_A0&& __a0) - {return __tree_.__emplace_unique(_VSTD::forward<_A0>(__a0));} - #ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> + template <class ..._Args> pair<iterator, bool> - emplace(_A0&& __a0, _Args&& ...__args); - -#endif // _LIBCPP_HAS_NO_VARIADICS - - _LIBCPP_INLINE_VISIBILITY - iterator - emplace_hint(const_iterator __p) - {return __tree_.__emplace_hint_unique(__p.__i_);} - - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - _LIBCPP_INLINE_VISIBILITY - iterator - emplace_hint(const_iterator __p, _A0&& __a0) - {return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_A0>(__a0));} - -#ifndef _LIBCPP_HAS_NO_VARIADICS + emplace(_Args&& ...__args); - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> + template <class ..._Args> iterator - emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); + emplace_hint(const_iterator __p, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS @@ -1015,13 +985,23 @@ private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - __node_holder __construct_node(_A0&& __a0); + template <class _A0> + typename enable_if + < + is_constructible<value_type, _A0>::value, + __node_holder + >::type + __construct_node(_A0&& __a0); + template <class _A0> + typename enable_if + < + is_constructible<key_type, _A0>::value, + __node_holder + >::type + __construct_node(_A0&& __a0); #ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> - __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); + template <class _A0, class _A1, class ..._Args> + __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(const key_type& __k); @@ -1215,9 +1195,12 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node() } template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, - class> -typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +template <class _A0> +typename enable_if +< + is_constructible<pair<const _Key, _Tp>, _A0>::value, + typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +>::type map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); @@ -1228,19 +1211,37 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) return __h; } +template <class _Key, class _Tp, class _Compare, class _Allocator> +template <class _A0> +typename enable_if +< + is_constructible<_Key, _A0>::value, + typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder +>::type +map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return __h; +} + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class> +template <class _A0, class _A1, class ..._Args> typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder -map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) +map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), + _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1), + _VSTD::forward<_Args>(__args)...); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...); __h.get_deleter().__second_constructed = true; return __h; } @@ -1329,14 +1330,11 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class //= typename enable_if<is_constructible<_Key, _A0>::value>::type - > +template <class ..._Args> pair<typename map<_Key, _Tp, _Compare, _Allocator>::iterator, bool> -map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) +map<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args) { - __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), - _VSTD::forward<_Args>(__args)...); + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); pair<iterator, bool> __r = __tree_.__node_insert_unique(__h.get()); if (__r.second) __h.release(); @@ -1344,15 +1342,12 @@ map<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) } template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class //= typename enable_if<is_constructible<_Key, _A0>::value>::type - > +template <class ..._Args> typename map<_Key, _Tp, _Compare, _Allocator>::iterator map<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, - _A0&& __a0, _Args&& ...__args) + _Args&& ...__args) { - __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), - _VSTD::forward<_Args>(__args)...); + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __tree_.__node_insert_unique(__p.__i_, __h.get()); if (__r.__i_.__ptr_ == __h.get()) __h.release(); @@ -1629,43 +1624,15 @@ public: {return value_compare(__tree_.value_comp().key_comp());} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - - _LIBCPP_INLINE_VISIBILITY - iterator emplace() {return __tree_.__emplace_multi();} - - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - _LIBCPP_INLINE_VISIBILITY - iterator - emplace(_A0&& __a0) - {return __tree_.__emplace_multi(_VSTD::forward<_A0>(__a0));} - #ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> + template <class ..._Args> iterator - emplace(_A0&& __a0, _Args&& ...__args); - -#endif // _LIBCPP_HAS_NO_VARIADICS + emplace(_Args&& ...__args); - _LIBCPP_INLINE_VISIBILITY - iterator emplace_hint(const_iterator __p) - {return __tree_.__emplace_hint_multi(__p.__i_);} - - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - _LIBCPP_INLINE_VISIBILITY - iterator - emplace_hint(const_iterator __p, _A0&& __a0) - {return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_A0>(__a0));} - -#ifndef _LIBCPP_HAS_NO_VARIADICS - - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> + template <class ..._Args> iterator - emplace_hint(const_iterator __p, _A0&& __a0, _Args&& ...__args); + emplace_hint(const_iterator __p, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS @@ -1757,13 +1724,23 @@ private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES __node_holder __construct_node(); - template <class _A0, - class = typename enable_if<is_constructible<value_type, _A0>::value>::type> - __node_holder __construct_node(_A0&& __a0); + template <class _A0> + typename enable_if + < + is_constructible<value_type, _A0>::value, + __node_holder + >::type + __construct_node(_A0&& __a0); + template <class _A0> + typename enable_if + < + is_constructible<key_type, _A0>::value, + __node_holder + >::type + __construct_node(_A0&& __a0); #ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _A0, class ..._Args, - class = typename enable_if<is_constructible<key_type, _A0>::value>::type> - __node_holder __construct_node(_A0&& __a0, _Args&& ...__args); + template <class _A0, class _A1, class ..._Args> + __node_holder __construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args); #endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }; @@ -1797,10 +1774,12 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node() } template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, - class // = typename enable_if<is_constructible<value_type, _A0>::value>::type - > -typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +template <class _A0> +typename enable_if +< + is_constructible<pair<const _Key, _Tp>, _A0>::value, + typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +>::type multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); @@ -1811,20 +1790,37 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) return __h; } +template <class _Key, class _Tp, class _Compare, class _Allocator> +template <class _A0> +typename enable_if +< + is_constructible<_Key, _A0>::value, + typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder +>::type +multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) +{ + __node_allocator& __na = __tree_.__node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __h.get_deleter().__first_constructed = true; + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __h.get_deleter().__second_constructed = true; + return __h; +} + #ifndef _LIBCPP_HAS_NO_VARIADICS template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class // = typename enable_if<is_constructible<key_type, _A0>::value>::type - > +template <class _A0, class _A1, class ..._Args> typename multimap<_Key, _Tp, _Compare, _Allocator>::__node_holder -multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& ...__args) +multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _A1&& __a1, _Args&& ...__args) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_), + _VSTD::forward<_A0>(__a0), _VSTD::forward<_A1>(__a1), + _VSTD::forward<_Args>(__args)...); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second), _VSTD::forward<_Args>(__args)...); __h.get_deleter().__second_constructed = true; return __h; } @@ -1835,30 +1831,23 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0, _Args&& #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class //= typename enable_if<is_constructible<_Key, _A0>::value>::type - > +template <class ..._Args> typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator -multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_A0&& __a0, _Args&& ...__args) +multimap<_Key, _Tp, _Compare, _Allocator>::emplace(_Args&& ...__args) { - __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), - _VSTD::forward<_Args>(__args)...); + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __tree_.__node_insert_multi(__h.get()); __h.release(); return __r; } template <class _Key, class _Tp, class _Compare, class _Allocator> -template <class _A0, class ..._Args, - class //= typename enable_if<is_constructible<_Key, _A0>::value>::type - > +template <class ..._Args> typename multimap<_Key, _Tp, _Compare, _Allocator>::iterator multimap<_Key, _Tp, _Compare, _Allocator>::emplace_hint(const_iterator __p, - _A0&& __a0, _Args&& ...__args) { - __node_holder __h = __construct_node(_VSTD::forward<_A0>(__a0), - _VSTD::forward<_Args>(__args)...); + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); iterator __r = __tree_.__node_insert_multi(__p.__i_, __h.get()); __h.release(); return __r; |