diff --git a/src/memory.h b/src/memory.h index e276d875..08a35217 100644 --- a/src/memory.h +++ b/src/memory.h @@ -106,13 +106,14 @@ namespace etl typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type(value); ++o_begin; - ++count; } return o_end; @@ -136,42 +137,42 @@ namespace etl template inline TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T& value, TCounter& count) { - return etl::uninitialized_fill(o_begin, o_begin + n, value, count); + count += n; + + return etl::uninitialized_fill(o_begin, o_begin + n, value); } //***************************************************************************** /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template + template typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { - TOutputIterator o_end = std::copy(i_begin, i_end, o_begin); - count += std::distance(o_begin, o_end); - - return o_end; + return std::copy(i_begin, i_end, o_begin); } //***************************************************************************** /// Copies a range of objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template + template typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin) { typedef typename std::iterator_traits::value_type value_type; + TOutputIterator o_end = o_begin; + while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); ++i_begin; - ++o_begin; - ++count; + ++o_end; } - return o_begin; + return o_end; } //***************************************************************************** @@ -200,15 +201,18 @@ namespace etl { typedef typename std::iterator_traits::value_type value_type; + TOutputIterator o_end = o_begin; + while (i_begin != i_end) { - ::new (static_cast(etl::addressof(*o_begin))) value_type(*i_begin); + ::new (static_cast(etl::addressof(*o_end))) value_type(*i_begin); ++i_begin; - ++o_begin; - ++count; + ++o_end; } - return o_begin; + count += std::distance(o_begin, o_end); + + return o_end; } //***************************************************************************** @@ -229,7 +233,9 @@ namespace etl template inline TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count) { - return etl::uninitialized_copy(i_begin, i_begin + n, o_begin, count); + count += n; + + return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } //***************************************************************************** @@ -238,7 +244,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, void>::type - uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end) + uninitialized_default_construct(TOutputIterator /*o_begin*/, TOutputIterator /*o_end*/) { } @@ -280,13 +286,14 @@ namespace etl typename etl::enable_if::value_type>::value, void>::type uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type; ++o_begin; - ++count; } } @@ -295,7 +302,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -308,7 +315,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { TOutputIterator o_end = o_begin + n; @@ -324,7 +331,7 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; @@ -340,12 +347,14 @@ namespace etl ///\ingroup memory //***************************************************************************** template - typename etl::enable_if::value_type>::value, TOutputIterator>::type + typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count) { TOutputIterator o_end = o_begin + n; - etl::uninitialized_default_construct(o_begin, o_end, count); + etl::uninitialized_default_construct(o_begin, o_end); + + count += n; return o_end; } @@ -374,13 +383,14 @@ namespace etl template void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count) { + count += std::distance(o_begin, o_end); + typedef typename std::iterator_traits::value_type value_type; while (o_begin != o_end) { ::new (static_cast(etl::addressof(*o_begin))) value_type(); - ++o_begin; - ++count; + ++o_begin; } } @@ -408,7 +418,9 @@ namespace etl { TOutputIterator o_end = o_begin + n; - etl::uninitialized_value_construct(o_begin, o_end, count); + etl::uninitialized_value_construct(o_begin, o_end); + + count += n; return o_end; } @@ -419,7 +431,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - destroy_at(T* p) + destroy_at(T* /*p*/) { } @@ -441,7 +453,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value, void>::type - destroy_at(T* p, TCounter& count) + destroy_at(T* /*p*/, TCounter& count) { --count; } @@ -465,7 +477,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, void>::type - destroy(TIterator i_begin, TIterator i_end) + destroy(TIterator /*i_begin*/, TIterator /*i_end*/) { } @@ -564,12 +576,13 @@ namespace etl typename etl::enable_if::value_type>::value, TIterator>::type destroy_n(TIterator i_begin, TSize n, TCounter& count) { + count -= n; + while (n > 0) { etl::destroy_at(etl::addressof(*i_begin)); ++i_begin; --n; - --count; } return i_begin;