Second half of C++17's splicing maps and sets
This commit adds a merge member function to all the map and set containers,
which splices nodes from the source container. This completes support for
P0083r3.
Differential revision: https://reviews.llvm.org/D48896
llvm-svn: 345744
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 5c4e07ae5c6f7f467b436f1b24f41ef4cf9897b3
diff --git a/include/map b/include/map
index cfd8280..472ac31 100644
--- a/include/map
+++ b/include/map
@@ -167,6 +167,15 @@
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
+ template<class C2>
+ void merge(map<Key, T, C2, Allocator>& source); // C++17
+ template<class C2>
+ void merge(map<Key, T, C2, Allocator>&& source); // C++17
+ template<class C2>
+ void merge(multimap<Key, T, C2, Allocator>& source); // C++17
+ template<class C2>
+ void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
+
void swap(map& m)
noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
is_nothrow_swappable<key_compare>::value); // C++17
@@ -368,6 +377,15 @@
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
+ template<class C2>
+ void merge(multimap<Key, T, C2, Allocator>& source); // C++17
+ template<class C2>
+ void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
+ template<class C2>
+ void merge(map<Key, T, C2, Allocator>& source); // C++17
+ template<class C2>
+ void merge(map<Key, T, C2, Allocator>&& source); // C++17
+
void swap(multimap& m)
noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
is_nothrow_swappable<key_compare>::value); // C++17
@@ -926,6 +944,11 @@
typedef __insert_return_type<iterator, node_type> insert_return_type;
#endif
+ template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
+ friend class _LIBCPP_TEMPLATE_VIS map;
+ template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
+ friend class _LIBCPP_TEMPLATE_VIS multimap;
+
_LIBCPP_INLINE_VISIBILITY
map()
_NOEXCEPT_(
@@ -1300,6 +1323,38 @@
{
return __tree_.template __node_handle_extract<node_type>(__it.__i_);
}
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(map<key_type, mapped_type, _C2, allocator_type>& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ __tree_.__node_handle_merge_unique(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(map<key_type, mapped_type, _C2, allocator_type>&& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ __tree_.__node_handle_merge_unique(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(multimap<key_type, mapped_type, _C2, allocator_type>& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ __tree_.__node_handle_merge_unique(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(multimap<key_type, mapped_type, _C2, allocator_type>&& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ __tree_.__node_handle_merge_unique(__source.__tree_);
+ }
#endif
_LIBCPP_INLINE_VISIBILITY
@@ -1615,6 +1670,11 @@
typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
#endif
+ template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
+ friend class _LIBCPP_TEMPLATE_VIS map;
+ template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
+ friend class _LIBCPP_TEMPLATE_VIS multimap;
+
_LIBCPP_INLINE_VISIBILITY
multimap()
_NOEXCEPT_(
@@ -1882,6 +1942,38 @@
return __tree_.template __node_handle_extract<node_type>(
__it.__i_);
}
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(multimap<key_type, mapped_type, _C2, allocator_type>& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ return __tree_.__node_handle_merge_multi(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(multimap<key_type, mapped_type, _C2, allocator_type>&& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ return __tree_.__node_handle_merge_multi(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(map<key_type, mapped_type, _C2, allocator_type>& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ return __tree_.__node_handle_merge_multi(__source.__tree_);
+ }
+ template <class _C2>
+ _LIBCPP_INLINE_VISIBILITY
+ void merge(map<key_type, mapped_type, _C2, allocator_type>&& __source)
+ {
+ _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
+ "merging container with incompatible allocator");
+ return __tree_.__node_handle_merge_multi(__source.__tree_);
+ }
#endif
_LIBCPP_INLINE_VISIBILITY