diff options
Diffstat (limited to 'libstdc++-v3/include/bits/stl_uninitialized.h')
-rw-r--r-- | libstdc++-v3/include/bits/stl_uninitialized.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/stl_uninitialized.h b/libstdc++-v3/include/bits/stl_uninitialized.h index c740503052b..94c7e151e29 100644 --- a/libstdc++-v3/include/bits/stl_uninitialized.h +++ b/libstdc++-v3/include/bits/stl_uninitialized.h @@ -879,6 +879,68 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif +#if __cplusplus >= 201103L + template<typename _Tp, typename _Up, typename _Allocator> + inline void + __relocate_object_a(_Tp* __dest, _Up* __orig, _Allocator& __alloc) + noexcept(noexcept(std::allocator_traits<_Allocator>::construct(__alloc, + __dest, std::move(*__orig))) + && noexcept(std::allocator_traits<_Allocator>::destroy( + __alloc, std::__addressof(*__orig)))) + { + typedef std::allocator_traits<_Allocator> __traits; + __traits::construct(__alloc, __dest, std::move(*__orig)); + __traits::destroy(__alloc, std::__addressof(*__orig)); + } + + // This class may be specialized for specific types. + template<typename _Tp> + struct __is_trivially_relocatable + : is_trivial<_Tp> { }; + + template <typename _Tp, typename _Up> + inline __enable_if_t<std::__is_trivially_relocatable<_Tp>::value, _Tp*> + __relocate_a_1(_Tp* __first, _Tp* __last, + _Tp* __result, allocator<_Up>& __alloc) + { + ptrdiff_t __count = __last - __first; + __builtin_memmove(__result, __first, __count * sizeof(_Tp)); + return __result + __count; + } + + template <typename _InputIterator, typename _ForwardIterator, + typename _Allocator> + inline _ForwardIterator + __relocate_a_1(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result, _Allocator& __alloc) + { + typedef typename iterator_traits<_InputIterator>::value_type + _ValueType; + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType2; + static_assert(std::is_same<_ValueType, _ValueType2>::value); + static_assert(noexcept(std::__relocate_object_a(std::addressof(*__result), + std::addressof(*__first), + __alloc))); + _ForwardIterator __cur = __result; + for (; __first != __last; ++__first, (void)++__cur) + std::__relocate_object_a(std::__addressof(*__cur), + std::__addressof(*__first), __alloc); + return __cur; + } + + template <typename _InputIterator, typename _ForwardIterator, + typename _Allocator> + inline _ForwardIterator + __relocate_a(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result, _Allocator& __alloc) + { + return __relocate_a_1(std::__niter_base(__first), + std::__niter_base(__last), + std::__niter_base(__result), __alloc); + } +#endif + _GLIBCXX_END_NAMESPACE_VERSION } // namespace |