@@ -201,18 +201,8 @@ namespace ranges
_Iter
operator()(_Iter __first, _Sent __last) const
{
- using _ValueType = remove_reference_t<iter_reference_t<_Iter>>;
- if constexpr (is_trivial_v<_ValueType>
- && is_copy_assignable_v<_ValueType>)
- return ranges::fill(__first, __last, _ValueType());
- else
- {
- auto __guard = __detail::_DestroyGuard(__first);
- for (; __first != __last; ++__first)
- ::new (__detail::__voidify(*__first)) _ValueType();
- __guard.release();
- return __first;
- }
+ return std::__uninitialized_default(std::move(__first),
+ std::move(__last));
}
template<__detail::__nothrow_forward_range _Range>
@@ -234,18 +224,7 @@ namespace ranges
_Iter
operator()(_Iter __first, iter_difference_t<_Iter> __n) const
{
- using _ValueType = remove_reference_t<iter_reference_t<_Iter>>;
- if constexpr (is_trivial_v<_ValueType>
- && is_copy_assignable_v<_ValueType>)
- return ranges::fill_n(__first, __n, _ValueType());
- else
- {
- auto __guard = __detail::_DestroyGuard(__first);
- for (; __n > 0; ++__first, (void) --__n)
- ::new (__detail::__voidify(*__first)) _ValueType();
- __guard.release();
- return __first;
- }
+ return std::__uninitialized_default_n(std::move(__first), __n);
}
};
@@ -634,9 +634,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// __uninitialized_default
// Fills [first, last) with value-initialized value_types.
- template<typename _ForwardIterator>
- inline void
- __uninitialized_default(_ForwardIterator __first, _ForwardIterator __last)
+ template<typename _ForwardIterator, typename _Sentinel>
+ _GLIBCXX20_CONSTEXPR
+ inline _ForwardIterator
+ __uninitialized_default(_ForwardIterator __first, _Sentinel __last)
{
if constexpr (__is_random_access_iter<_ForwardIterator>::__value)
if (void* __ptr = std::__ptr_for_trivial_zero_init(__first))
@@ -649,14 +650,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const size_t __n = __dist;
__glibcxx_assert(__n < __SIZE_MAX__ / sizeof(_ValueType));
__builtin_memset(__ptr, 0, __n * sizeof(_ValueType));
+ return __first + __dist;
}
- return;
+ return __first;
}
_UninitDestroyGuard<_ForwardIterator> __guard(__first);
for (; __first != __last; ++__first)
std::_Construct(std::__addressof(*__first));
__guard.release();
+ return __first;
}
// __uninitialized_default_n
@@ -939,7 +942,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
uninitialized_value_construct(_ForwardIterator __first,
_ForwardIterator __last)
{
- return std::__uninitialized_default(__first, __last);
+ std::__uninitialized_default(__first, __last);
}
/**