#ifndef _UNINITIALIZED_FUNCTIONS_H_ #define _UNINITIALIZED_FUNCTIONS_H_ #include "Algorithm.h" #include "Construct.h" #include "Iterator.h" #include "TypeTraits.h" namespace TinySTL{ /***************************************************************************/ template ForwardIterator _uninitialized_copy_aux(InputIterator first, InputIterator last, ForwardIterator result, _true_type); template ForwardIterator _uninitialized_copy_aux(InputIterator first, InputIterator last, ForwardIterator result, _false_type); template ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result){ typedef typename _type_traits::value_type>::is_POD_type isPODType; return _uninitialized_copy_aux(first, last, result, isPODType()); } template ForwardIterator _uninitialized_copy_aux(InputIterator first, InputIterator last, ForwardIterator result, _true_type){ memcpy(result, first, (last - first) * sizeof(*first)); return result + (last - first); } template ForwardIterator _uninitialized_copy_aux(InputIterator first, InputIterator last, ForwardIterator result, _false_type){ int i = 0; for (; first != last; ++first, ++i){ construct((result + i), *first); } return (result + i); } /***************************************************************************/ template void _uninitialized_fill_aux(ForwardIterator first, ForwardIterator last, const T& value, _true_type); template void _uninitialized_fill_aux(ForwardIterator first, ForwardIterator last, const T& value, _false_type); template void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& value){ typedef typename _type_traits::is_POD_type isPODType; _uninitialized_fill_aux(first, last, value, isPODType()); } template void _uninitialized_fill_aux(ForwardIterator first, ForwardIterator last, const T& value, _true_type){ fill(first, last, value); } template void _uninitialized_fill_aux(ForwardIterator first, ForwardIterator last, const T& value, _false_type){ for (; first != last; ++first){ construct(first, value); } } /***************************************************************************/ template ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first, Size n, const T& x, _true_type); template ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first, Size n, const T& x, _false_type); template inline ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n, const T& x){ typedef typename _type_traits::is_POD_type isPODType; return _uninitialized_fill_n_aux(first, n, x, isPODType()); } template ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first, Size n, const T& x, _true_type){ return fill_n(first, n, x); } template ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first, Size n, const T& x, _false_type){ int i = 0; for (; i != n; ++i){ construct((T*)(first + i), x); } return (first + i); } } #endif