68 #ifndef EASTL_MEMORY_H 69 #define EASTL_MEMORY_H 72 #include <stk_util/util/config_eastl.h> 73 #include <stk_util/util/generic_iterator_eastl.h> 74 #include <stk_util/util/type_traits_eastl.h> 75 #include <stk_util/util/algorithm_eastl.h> 76 #include <stk_util/util/allocator_eastl.h> 79 #pragma warning(push, 0) 88 #pragma warning(disable: 4530) // C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc 99 #ifndef EASTL_TEMP_DEFAULT_NAME 100 #define EASTL_TEMP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " temp" // Unless the user overrides something, this is "EASTL temp". 121 template <
typename T>
124 EASTLAllocatorType
allocator(*EASTLAllocatorDefault(), pName);
142 template <
typename T>
145 EASTLAllocatorType&
allocator(*EASTLAllocatorDefault());
169 template <
bool hasTrivialMove,
typename iteratorTag>
172 template <
typename ForwardIterator,
typename ForwardIteratorDest>
173 static ForwardIteratorDest do_move_start(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
175 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
177 #if EASTL_EXCEPTIONS_ENABLED 178 ForwardIteratorDest origDest(dest);
181 for(; first != last; ++first, ++dest)
182 ::
new(&*dest) value_type(*first);
186 for(; origDest < dest; ++origDest)
187 origDest->~value_type();
191 for(; first != last; ++first, ++dest)
192 ::
new(&*dest) value_type(*first);
198 template <
typename ForwardIterator,
typename ForwardIteratorDest>
199 static ForwardIteratorDest do_move_commit(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
201 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
202 for(; first != last; ++first, ++dest)
203 first->~value_type();
208 template <
typename ForwardIterator,
typename ForwardIteratorDest>
209 static ForwardIteratorDest do_move_abort(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
211 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
212 for(; first != last; ++first, ++dest)
221 template <
typename T>
222 static T* do_move_start(T* first, T* last, T* dest)
224 return (T*)memcpy(dest, first, (
size_t)((uintptr_t)last - (uintptr_t)first)) + (last - first);
227 template <
typename T>
228 static T* do_move_commit(T* first, T* last, T* dest)
230 return dest + (last - first);
233 template <
typename T>
234 static T* do_move_abort(T* first, T* last, T* dest)
236 return dest + (last - first);
265 template <
typename ForwardIterator,
typename ForwardIteratorDest>
268 typedef typename eastl::iterator_traits<ForwardIterator>::iterator_category IC;
269 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type_input;
270 typedef typename eastl::iterator_traits<ForwardIteratorDest>::value_type value_type_output;
272 const bool bHasTrivialMove = type_and<has_trivial_relocate<value_type_input>::value,
273 is_pointer<ForwardIterator>::value,
274 is_pointer<ForwardIteratorDest>::value,
275 is_same<value_type_input, value_type_output>::value>::value;
280 template <
typename ForwardIterator,
typename ForwardIteratorDest>
281 inline ForwardIteratorDest uninitialized_move_commit(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
283 typedef typename eastl::iterator_traits<ForwardIterator>::iterator_category IC;
284 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type_input;
285 typedef typename eastl::iterator_traits<ForwardIteratorDest>::value_type value_type_output;
287 const bool bHasTrivialMove = type_and<has_trivial_relocate<value_type_input>::value,
288 is_pointer<ForwardIterator>::value,
289 is_pointer<ForwardIteratorDest>::value,
290 is_same<value_type_input, value_type_output>::value>::value;
295 template <
typename ForwardIterator,
typename ForwardIteratorDest>
296 inline ForwardIteratorDest uninitialized_move_abort(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
298 typedef typename eastl::iterator_traits<ForwardIterator>::iterator_category IC;
299 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type_input;
300 typedef typename eastl::iterator_traits<ForwardIteratorDest>::value_type value_type_output;
302 const bool bHasTrivialMove = type_and<has_trivial_relocate<value_type_input>::value,
303 is_pointer<ForwardIterator>::value,
304 is_pointer<ForwardIteratorDest>::value,
305 is_same<value_type_input, value_type_output>::value>::value;
317 template <
typename ForwardIterator,
typename ForwardIteratorDest>
318 inline ForwardIteratorDest
uninitialized_move(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
321 uninitialized_move_commit(first, last, dest);
332 template <
typename InputIterator,
typename ForwardIterator>
333 inline ForwardIterator uninitialized_copy_impl(InputIterator first, InputIterator last, ForwardIterator dest, true_type)
338 template <
typename InputIterator,
typename ForwardIterator>
339 inline ForwardIterator uninitialized_copy_impl(InputIterator first, InputIterator last, ForwardIterator dest, false_type)
341 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
342 ForwardIterator currentDest(dest);
344 #if EASTL_EXCEPTIONS_ENABLED 347 for(; first != last; ++first, ++currentDest)
348 ::
new(&*currentDest) value_type(*first);
352 for(; dest < currentDest; ++dest)
357 for(; first != last; ++first, ++currentDest)
358 ::
new(&*currentDest) value_type(*first);
378 template <
typename InputIterator,
typename ForwardIterator>
379 inline ForwardIterator
uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result)
381 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
387 return uninitialized_copy_impl(first, last, result, has_trivial_assign<value_type>());
396 template <
typename First,
typename Last,
typename Result>
399 typedef typename eastl::iterator_traits<generic_iterator<Result, void> >::value_type value_type;
403 has_trivial_assign<value_type>()));
412 template <
typename ForwardIterator,
typename T>
413 inline void uninitialized_fill_impl(ForwardIterator first, ForwardIterator last,
const T& value, true_type)
418 template <
typename ForwardIterator,
typename T>
419 void uninitialized_fill_impl(ForwardIterator first, ForwardIterator last,
const T& value, false_type)
421 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
422 ForwardIterator currentDest(first);
424 #if EASTL_EXCEPTIONS_ENABLED 427 for(; currentDest != last; ++currentDest)
428 ::
new(&*currentDest) value_type(value);
432 for(; first < currentDest; ++first)
433 first->~value_type();
437 for(; currentDest != last; ++currentDest)
438 ::
new(&*currentDest) value_type(value);
452 template <
typename ForwardIterator,
typename T>
455 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
456 uninitialized_fill_impl(first, last, value, has_trivial_assign<value_type>());
465 template <
typename T>
468 typedef typename eastl::iterator_traits<generic_iterator<T*, void> >::value_type value_type;
477 template <
typename ForwardIterator,
typename Count,
typename T>
478 inline void uninitialized_fill_n_impl(ForwardIterator first, Count n,
const T& value, true_type)
483 template <
typename ForwardIterator,
typename Count,
typename T>
484 void uninitialized_fill_n_impl(ForwardIterator first, Count n,
const T& value, false_type)
486 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
487 ForwardIterator currentDest(first);
489 #if EASTL_EXCEPTIONS_ENABLED 492 for(; n > 0; --n, ++currentDest)
493 ::
new(&*currentDest) value_type(value);
497 for(; first < currentDest; ++first)
498 first->~value_type();
502 for(; n > 0; --n, ++currentDest)
503 ::
new(&*currentDest) value_type(value);
517 template <
typename ForwardIterator,
typename Count,
typename T>
520 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
521 uninitialized_fill_n_impl(first, n, value, has_trivial_assign<value_type>());
530 template <
typename T,
typename Count>
533 typedef typename eastl::iterator_traits<generic_iterator<T*, void> >::value_type value_type;
545 template <
typename InputIterator,
typename ForwardIterator,
typename T>
547 ForwardIterator first2, ForwardIterator last2,
const T& value)
551 #if EASTL_EXCEPTIONS_ENABLED 556 #if EASTL_EXCEPTIONS_ENABLED 560 for(; first2 < mid; ++first2)
561 first2->~value_type();
575 template <
typename ForwardIterator,
typename T,
typename InputIterator>
576 inline ForwardIterator
581 #if EASTL_EXCEPTIONS_ENABLED 586 #if EASTL_EXCEPTIONS_ENABLED 590 for(; result < mid; ++result)
591 result->~value_type();
604 template <
typename InputIterator1,
typename InputIterator2,
typename ForwardIterator>
605 inline ForwardIterator
607 InputIterator2 first2, InputIterator2 last2,
608 ForwardIterator result)
612 #if EASTL_EXCEPTIONS_ENABLED 617 #if EASTL_EXCEPTIONS_ENABLED 621 for(; result < mid; ++result)
622 result->~value_type();
639 template <
typename T>
649 template <
typename ForwardIterator>
650 inline void destruct_impl(ForwardIterator , ForwardIterator , true_type)
655 template <
typename ForwardIterator>
656 inline void destruct_impl(ForwardIterator first, ForwardIterator last, false_type)
658 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
660 for(; first != last; ++first)
661 (*first).~value_type();
671 template <
typename ForwardIterator>
672 inline void destruct(ForwardIterator first, ForwardIterator last)
674 typedef typename eastl::iterator_traits<ForwardIterator>::value_type value_type;
675 destruct_impl(first, last, eastl::has_trivial_destructor<value_type>());
687 #endif // Header include guard
OutputIterator fill_n(OutputIterator first, Size n, const T &value)
void uninitialized_copy_fill(InputIterator first1, InputIterator last1, ForwardIterator first2, ForwardIterator last2, const T &value)
ForwardIterator uninitialized_copy_copy(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, ForwardIterator result)
void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T &value)
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
void uninitialized_fill_n(ForwardIterator first, Count n, const T &value)
void uninitialized_fill_n_ptr(T *first, Count n, const T &value)
void uninitialized_fill_ptr(T *first, T *last, const T &value)
ForwardIterator uninitialized_fill_copy(ForwardIterator result, ForwardIterator mid, const T &value, InputIterator first, InputIterator last)
ForwardIteratorDest uninitialized_move_start(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
ForwardIteratorDest uninitialized_move(ForwardIterator first, ForwardIterator last, ForwardIteratorDest dest)
Result uninitialized_copy_ptr(First first, Last last, Result result)
void return_temporary_buffer(T *p, ptrdiff_t n=0)
pair< T *, ptrdiff_t > get_temporary_buffer(ptrdiff_t n, size_t alignment=0, size_t alignmentOffset=0, const char *pName=EASTL_DEFAULT_NAME_PREFIX " temp")
void fill(ForwardIterator first, ForwardIterator last, const T &value)
EA Standard Template Library.
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result)