Skip to content

Commit 8c5fb9b

Browse files
mtezychldionne
authored andcommitted
[libc++][vector] Inline remaining constructors filling vector with the same value
1 parent b4df0da commit 8c5fb9b

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

libcxx/include/vector

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,36 @@ public:
423423
#endif
424424
: __end_cap_(nullptr, __a) {
425425
}
426-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
426+
427+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
428+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
429+
if (__n > 0) {
430+
__vallocate(__n);
431+
__construct_at_end(__n);
432+
}
433+
__guard.__complete();
434+
}
435+
427436
#if _LIBCPP_STD_VER >= 14
428-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a);
437+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a)
438+
: __end_cap_(nullptr, __a) {
439+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
440+
if (__n > 0) {
441+
__vallocate(__n);
442+
__construct_at_end(__n);
443+
}
444+
__guard.__complete();
445+
}
429446
#endif
430-
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
447+
448+
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {
449+
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
450+
if (__n > 0) {
451+
__vallocate(__n);
452+
__construct_at_end(__n, __x);
453+
}
454+
__guard.__complete();
455+
}
431456

432457
template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
433458
_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
@@ -1132,39 +1157,6 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type _
11321157
}
11331158
}
11341159

1135-
template <class _Tp, class _Allocator>
1136-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) {
1137-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1138-
if (__n > 0) {
1139-
__vallocate(__n);
1140-
__construct_at_end(__n);
1141-
}
1142-
__guard.__complete();
1143-
}
1144-
1145-
#if _LIBCPP_STD_VER >= 14
1146-
template <class _Tp, class _Allocator>
1147-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1148-
: __end_cap_(nullptr, __a) {
1149-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1150-
if (__n > 0) {
1151-
__vallocate(__n);
1152-
__construct_at_end(__n);
1153-
}
1154-
__guard.__complete();
1155-
}
1156-
#endif
1157-
1158-
template <class _Tp, class _Allocator>
1159-
_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) {
1160-
auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1161-
if (__n > 0) {
1162-
__vallocate(__n);
1163-
__construct_at_end(__n, __x);
1164-
}
1165-
__guard.__complete();
1166-
}
1167-
11681160
template <class _Tp, class _Allocator>
11691161
template <class _InputIterator,
11701162
__enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&

0 commit comments

Comments
 (0)