Skip to content

Commit bdbac2b

Browse files
authored
[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.
1 parent 22f8ced commit bdbac2b

File tree

2 files changed

+11
-50
lines changed

2 files changed

+11
-50
lines changed

libcxx/include/map

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -972,31 +972,15 @@ public:
972972

973973
_LIBCPP_HIDE_FROM_ABI map(const map& __m) : __tree_(__m.__tree_) { insert(__m.begin(), __m.end()); }
974974

975-
_LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) {
976-
# ifndef _LIBCPP_CXX03_LANG
977-
__tree_ = __m.__tree_;
978-
# else
979-
if (this != std::addressof(__m)) {
980-
__tree_.clear();
981-
__tree_.value_comp() = __m.__tree_.value_comp();
982-
__tree_.__copy_assign_alloc(__m.__tree_);
983-
insert(__m.begin(), __m.end());
984-
}
985-
# endif
986-
return *this;
987-
}
975+
_LIBCPP_HIDE_FROM_ABI map& operator=(const map& __m) = default;
988976

989977
# ifndef _LIBCPP_CXX03_LANG
990978

991-
_LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
992-
: __tree_(std::move(__m.__tree_)) {}
979+
_LIBCPP_HIDE_FROM_ABI map(map&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
993980

994981
_LIBCPP_HIDE_FROM_ABI map(map&& __m, const allocator_type& __a);
995982

996-
_LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
997-
__tree_ = std::move(__m.__tree_);
998-
return *this;
999-
}
983+
_LIBCPP_HIDE_FROM_ABI map& operator=(map&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
1000984

1001985
_LIBCPP_HIDE_FROM_ABI map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
1002986
: __tree_(__vc(__comp)) {
@@ -1659,31 +1643,16 @@ public:
16591643
insert(__m.begin(), __m.end());
16601644
}
16611645

1662-
_LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) {
1663-
# ifndef _LIBCPP_CXX03_LANG
1664-
__tree_ = __m.__tree_;
1665-
# else
1666-
if (this != std::addressof(__m)) {
1667-
__tree_.clear();
1668-
__tree_.value_comp() = __m.__tree_.value_comp();
1669-
__tree_.__copy_assign_alloc(__m.__tree_);
1670-
insert(__m.begin(), __m.end());
1671-
}
1672-
# endif
1673-
return *this;
1674-
}
1646+
_LIBCPP_HIDE_FROM_ABI multimap& operator=(const multimap& __m) = default;
16751647

16761648
# ifndef _LIBCPP_CXX03_LANG
16771649

1678-
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value)
1679-
: __tree_(std::move(__m.__tree_)) {}
1650+
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m) noexcept(is_nothrow_move_constructible<__base>::value) = default;
16801651

16811652
_LIBCPP_HIDE_FROM_ABI multimap(multimap&& __m, const allocator_type& __a);
16821653

1683-
_LIBCPP_HIDE_FROM_ABI multimap& operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) {
1684-
__tree_ = std::move(__m.__tree_);
1685-
return *this;
1686-
}
1654+
_LIBCPP_HIDE_FROM_ABI multimap&
1655+
operator=(multimap&& __m) noexcept(is_nothrow_move_assignable<__base>::value) = default;
16871656

16881657
_LIBCPP_HIDE_FROM_ABI multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
16891658
: __tree_(__vc(__comp)) {

libcxx/include/set

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,10 @@ public:
662662

663663
_LIBCPP_HIDE_FROM_ABI set(const set& __s) : __tree_(__s.__tree_) { insert(__s.begin(), __s.end()); }
664664

665-
_LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) {
666-
__tree_ = __s.__tree_;
667-
return *this;
668-
}
665+
_LIBCPP_HIDE_FROM_ABI set& operator=(const set& __s) = default;
669666

670667
# ifndef _LIBCPP_CXX03_LANG
671-
_LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
672-
: __tree_(std::move(__s.__tree_)) {}
668+
_LIBCPP_HIDE_FROM_ABI set(set&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
673669
# endif // _LIBCPP_CXX03_LANG
674670

675671
_LIBCPP_HIDE_FROM_ABI explicit set(const allocator_type& __a) : __tree_(__a) {}
@@ -1129,14 +1125,10 @@ public:
11291125
insert(__s.begin(), __s.end());
11301126
}
11311127

1132-
_LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) {
1133-
__tree_ = __s.__tree_;
1134-
return *this;
1135-
}
1128+
_LIBCPP_HIDE_FROM_ABI multiset& operator=(const multiset& __s) = default;
11361129

11371130
# ifndef _LIBCPP_CXX03_LANG
1138-
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value)
1139-
: __tree_(std::move(__s.__tree_)) {}
1131+
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s) noexcept(is_nothrow_move_constructible<__base>::value) = default;
11401132

11411133
_LIBCPP_HIDE_FROM_ABI multiset(multiset&& __s, const allocator_type& __a);
11421134
# endif // _LIBCPP_CXX03_LANG

0 commit comments

Comments
 (0)