Skip to content

Commit 03f92a9

Browse files
committed
[libc++] default the allocator arguemnt for most constructor
1 parent 1ab64e4 commit 03f92a9

File tree

1 file changed

+9
-38
lines changed

1 file changed

+9
-38
lines changed

libcxx/include/string

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,15 +1058,9 @@ public:
10581058
}
10591059
# endif // _LIBCPP_CXX03_LANG
10601060

1061-
template <__enable_if_t<__is_allocator_v<_Allocator>, int> = 0>
1062-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s) {
1063-
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*) detected nullptr");
1064-
__init(__s, traits_type::length(__s));
1065-
}
1066-
10671061
template <__enable_if_t<__is_allocator_v<_Allocator>, int> = 0>
10681062
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1069-
basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, const _Allocator& __a)
1063+
basic_string(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, const _Allocator& __a = _Allocator())
10701064
: __alloc_(__a) {
10711065
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
10721066
__init(__s, traits_type::length(__s));
@@ -1076,22 +1070,14 @@ public:
10761070
basic_string(nullptr_t) = delete;
10771071
# endif
10781072

1079-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n)
1080-
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
1081-
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1082-
__init(__s, __n);
1083-
}
1084-
10851073
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1086-
basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1074+
basic_string(const _CharT* __s, size_type __n, const _Allocator& __a = _Allocator())
10871075
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero")
10881076
: __alloc_(__a) {
10891077
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
10901078
__init(__s, __n);
10911079
}
10921080

1093-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) { __init(__n, __c); }
1094-
10951081
# if _LIBCPP_STD_VER >= 23
10961082
_LIBCPP_HIDE_FROM_ABI constexpr basic_string(
10971083
basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator())
@@ -1114,7 +1100,8 @@ public:
11141100
# endif
11151101

11161102
template <__enable_if_t<__is_allocator_v<_Allocator>, int> = 0>
1117-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a)
1103+
_LIBCPP_HIDE_FROM_ABI
1104+
_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a = _Allocator())
11181105
: __alloc_(__a) {
11191106
__init(__n, __c);
11201107
}
@@ -1153,29 +1140,16 @@ public:
11531140
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
11541141
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
11551142
int> = 0>
1156-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) {
1157-
__self_view __sv = __t;
1158-
__init(__sv.data(), __sv.size());
1159-
}
1160-
1161-
template <class _Tp,
1162-
__enable_if_t<__can_be_converted_to_string_view_v<_CharT, _Traits, _Tp> &&
1163-
!is_same<__remove_cvref_t<_Tp>, basic_string>::value,
1164-
int> = 0>
1165-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a)
1143+
_LIBCPP_HIDE_FROM_ABI
1144+
_LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t, const allocator_type& __a = allocator_type())
11661145
: __alloc_(__a) {
11671146
__self_view __sv = __t;
11681147
__init(__sv.data(), __sv.size());
11691148
}
11701149

1171-
template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
1172-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) {
1173-
__init(__first, __last);
1174-
}
1175-
11761150
template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0>
11771151
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1178-
basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1152+
basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a = allocator_type())
11791153
: __alloc_(__a) {
11801154
__init(__first, __last);
11811155
}
@@ -1194,11 +1168,8 @@ public:
11941168
# endif
11951169

11961170
# ifndef _LIBCPP_CXX03_LANG
1197-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) {
1198-
__init(__il.begin(), __il.end());
1199-
}
1200-
1201-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a)
1171+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1172+
basic_string(initializer_list<_CharT> __il, const _Allocator& __a = _Allocator())
12021173
: __alloc_(__a) {
12031174
__init(__il.begin(), __il.end());
12041175
}

0 commit comments

Comments
 (0)