[libc++] default some special members in map and set (#147081)

We don't actually do anything special in these special member functions,
so we can just `= default` them to save a bit of code.
This commit is contained in:
Nikolas Klauser 2025-07-05 18:09:40 +02:00 committed by GitHub
parent 22f8ceded4
commit bdbac2bb49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 50 deletions

View File

@ -972,31 +972,15 @@ public:
_LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
_LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
# ifndef _LIBCPP_CXX03_LANG
__tree_ = __m.__tree_;
# else
if (this != std::addressof(__m)) {
__tree_.clear();
__tree_.value_comp() = __m.__tree_.value_comp();
__tree_.__copy_assign_alloc(__m.__tree_);
insert(__m.begin(), __m.end());
}
# endif
return *this;
}
_LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) = default;
# ifndef _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
: __tree_(std::move(__m.__tree_)) {}
_LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
_LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
_LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
__tree_ = std::move(__m.__tree_);
return *this;
}
_LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
_LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp)) {
@ -1659,31 +1643,16 @@ public:
insert(__m.begin(), __m.end());
}
_LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
# ifndef _LIBCPP_CXX03_LANG
__tree_ = __m.__tree_;
# else
if (this != std::addressof(__m)) {
__tree_.clear();
__tree_.value_comp() = __m.__tree_.value_comp();
__tree_.__copy_assign_alloc(__m.__tree_);
insert(__m.begin(), __m.end());
}
# endif
return *this;
}
_LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) = default;
# ifndef _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
: __tree_(std::move(__m.__tree_)) {}
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a);
_LIBCPP_HIDE_FROM_ABI multimap& operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
__tree_ = std::move(__m.__tree_);
return *this;
}
_LIBCPP_HIDE_FROM_ABI multimap&
operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
_LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp)) {

View File

@ -662,14 +662,10 @@ public:
_LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
_LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) {
__tree_ = __s.__tree_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) = default;
# ifndef _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
: __tree_(std::move(__s.__tree_)) {}
_LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
# endif // _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
@ -1129,14 +1125,10 @@ public:
insert(__s.begin(), __s.end());
}
_LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) {
__tree_ = __s.__tree_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) = default;
# ifndef _LIBCPP_CXX03_LANG
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
: __tree_(std::move(__s.__tree_)) {}
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
# endif // _LIBCPP_CXX03_LANG