[libc++] Move <memory> helpers outside of std::allocator_traits
They don't really belong as members of allocator_traits.
This commit is contained in:
@@ -1458,118 +1458,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
|
||||
__has_select_on_container_copy_construction<const allocator_type>(),
|
||||
__a);}
|
||||
|
||||
template <class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
void
|
||||
__construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
|
||||
{
|
||||
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
|
||||
"The specified type does not meet the requirements of Cpp17MoveInsertible");
|
||||
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
|
||||
construct(__a, _VSTD::__to_address(__begin2),
|
||||
#ifdef _LIBCPP_NO_EXCEPTIONS
|
||||
_VSTD::move(*__begin1)
|
||||
#else
|
||||
_VSTD::move_if_noexcept(*__begin1)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
typename enable_if
|
||||
<
|
||||
(__is_default_allocator<allocator_type>::value
|
||||
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
|
||||
is_trivially_move_constructible<_Tp>::value,
|
||||
void
|
||||
>::type
|
||||
__construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
|
||||
{
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
if (_Np > 0)
|
||||
{
|
||||
_VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
|
||||
__begin2 += _Np;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Iter, class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
void
|
||||
__construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
|
||||
{
|
||||
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
|
||||
construct(__a, _VSTD::__to_address(__begin2), *__begin1);
|
||||
}
|
||||
|
||||
template <class _SourceTp, class _DestTp,
|
||||
class _RawSourceTp = typename remove_const<_SourceTp>::type,
|
||||
class _RawDestTp = typename remove_const<_DestTp>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
typename enable_if
|
||||
<
|
||||
is_trivially_copy_constructible<_DestTp>::value &&
|
||||
is_same<_RawSourceTp, _RawDestTp>::value &&
|
||||
(__is_default_allocator<allocator_type>::value ||
|
||||
!__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
|
||||
void
|
||||
>::type
|
||||
__construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
|
||||
{
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
if (_Np > 0)
|
||||
{
|
||||
_VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
|
||||
__begin2 += _Np;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
void
|
||||
__construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
|
||||
{
|
||||
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
|
||||
"The specified type does not meet the requirements of Cpp17MoveInsertable");
|
||||
while (__end1 != __begin1)
|
||||
{
|
||||
construct(__a, _VSTD::__to_address(__end2 - 1),
|
||||
#ifdef _LIBCPP_NO_EXCEPTIONS
|
||||
_VSTD::move(*--__end1)
|
||||
#else
|
||||
_VSTD::move_if_noexcept(*--__end1)
|
||||
#endif
|
||||
);
|
||||
--__end2;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
static
|
||||
typename enable_if
|
||||
<
|
||||
(__is_default_allocator<allocator_type>::value
|
||||
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
|
||||
is_trivially_move_constructible<_Tp>::value,
|
||||
void
|
||||
>::type
|
||||
__construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
|
||||
{
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
__end2 -= _Np;
|
||||
if (_Np > 0)
|
||||
_VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
static pointer __allocate(allocator_type& __a, size_type __n,
|
||||
const_void_pointer __hint, true_type)
|
||||
@@ -1822,6 +1711,93 @@ template <class _Tp, class _Up>
|
||||
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
||||
bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
|
||||
|
||||
template <class _Alloc, class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_forward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) {
|
||||
static_assert(__is_cpp17_move_insertable<_Alloc>::value,
|
||||
"The specified type does not meet the requirements of Cpp17MoveInsertible");
|
||||
typedef allocator_traits<_Alloc> _Traits;
|
||||
for (; __begin1 != __end1; ++__begin1, (void)++__begin2) {
|
||||
_Traits::construct(__a, _VSTD::__to_address(__begin2),
|
||||
#ifdef _LIBCPP_NO_EXCEPTIONS
|
||||
_VSTD::move(*__begin1)
|
||||
#else
|
||||
_VSTD::move_if_noexcept(*__begin1)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Alloc, class _Tp, typename enable_if<
|
||||
(__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) &&
|
||||
is_trivially_move_constructible<_Tp>::value
|
||||
>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_forward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) {
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
if (_Np > 0) {
|
||||
_VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
|
||||
__begin2 += _Np;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Alloc, class _Iter, class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_range_forward(_Alloc& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) {
|
||||
typedef allocator_traits<_Alloc> _Traits;
|
||||
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) {
|
||||
_Traits::construct(__a, _VSTD::__to_address(__begin2), *__begin1);
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Alloc, class _Source, class _Dest,
|
||||
class _RawSource = typename remove_const<_Source>::type,
|
||||
class _RawDest = typename remove_const<_Dest>::type,
|
||||
class =
|
||||
typename enable_if<
|
||||
is_trivially_copy_constructible<_Dest>::value &&
|
||||
is_same<_RawSource, _RawDest>::value &&
|
||||
(__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Dest*, _Source&>::value)
|
||||
>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_range_forward(_Alloc&, _Source* __begin1, _Source* __end1, _Dest*& __begin2) {
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
if (_Np > 0) {
|
||||
_VSTD::memcpy(const_cast<_RawDest*>(__begin2), __begin1, _Np * sizeof(_Dest));
|
||||
__begin2 += _Np;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Alloc, class _Ptr>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_backward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) {
|
||||
static_assert(__is_cpp17_move_insertable<_Alloc>::value,
|
||||
"The specified type does not meet the requirements of Cpp17MoveInsertable");
|
||||
typedef allocator_traits<_Alloc> _Traits;
|
||||
while (__end1 != __begin1) {
|
||||
_Traits::construct(__a, _VSTD::__to_address(__end2 - 1),
|
||||
#ifdef _LIBCPP_NO_EXCEPTIONS
|
||||
_VSTD::move(*--__end1)
|
||||
#else
|
||||
_VSTD::move_if_noexcept(*--__end1)
|
||||
#endif
|
||||
);
|
||||
--__end2;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Alloc, class _Tp, class = typename enable_if<
|
||||
(__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) &&
|
||||
is_trivially_move_constructible<_Tp>::value
|
||||
>::type>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void __construct_backward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) {
|
||||
ptrdiff_t _Np = __end1 - __begin1;
|
||||
__end2 -= _Np;
|
||||
if (_Np > 0)
|
||||
_VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
|
||||
}
|
||||
|
||||
template <class _OutputIterator, class _Tp>
|
||||
class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
|
||||
: public iterator<output_iterator_tag,
|
||||
|
||||
@@ -951,8 +951,7 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
|
||||
{
|
||||
|
||||
__annotate_delete();
|
||||
__alloc_traits::__construct_backward_with_exception_guarantees(
|
||||
this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
|
||||
__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
|
||||
_VSTD::swap(this->__begin_, __v.__begin_);
|
||||
_VSTD::swap(this->__end_, __v.__end_);
|
||||
_VSTD::swap(this->__end_cap(), __v.__end_cap());
|
||||
@@ -967,10 +966,8 @@ vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, a
|
||||
{
|
||||
__annotate_delete();
|
||||
pointer __r = __v.__begin_;
|
||||
__alloc_traits::__construct_backward_with_exception_guarantees(
|
||||
this->__alloc(), this->__begin_, __p, __v.__begin_);
|
||||
__alloc_traits::__construct_forward_with_exception_guarantees(
|
||||
this->__alloc(), __p, this->__end_, __v.__end_);
|
||||
__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
|
||||
__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
|
||||
_VSTD::swap(this->__begin_, __v.__begin_);
|
||||
_VSTD::swap(this->__end_, __v.__end_);
|
||||
_VSTD::swap(this->__end_cap(), __v.__end_cap());
|
||||
@@ -1077,7 +1074,7 @@ typename enable_if
|
||||
vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
|
||||
{
|
||||
_ConstructTransaction __tx(*this, __n);
|
||||
__alloc_traits::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
|
||||
__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
|
||||
}
|
||||
|
||||
// Default constructs __n objects starting at __end_
|
||||
|
||||
Reference in New Issue
Block a user