From 9300b00646474f1a678d86b89634b4413d5dd260 Mon Sep 17 00:00:00 2001 From: jwellbelove Date: Fri, 17 Feb 2017 11:21:21 +0000 Subject: [PATCH] Added... uninitialized_default_construct uninitialized_value_construct for single items. --- src/memory.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/memory.h b/src/memory.h index 69a3e3af..2f8597f4 100644 --- a/src/memory.h +++ b/src/memory.h @@ -56,7 +56,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, TOutputIterator>::type - uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value) + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value) { std::fill(o_begin, o_end, value); @@ -89,7 +89,7 @@ namespace etl //***************************************************************************** template typename etl::enable_if::value_type>::value, TOutputIterator>::type - uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, T value, TCounter& count) + uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T& value, TCounter& count) { std::fill(o_begin, o_end, value); count += std::distance(o_begin, o_end); @@ -238,6 +238,50 @@ namespace etl return etl::uninitialized_copy(i_begin, i_begin + n, o_begin); } + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* /*p*/) + { + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* /*p*/, TCounter& count) + { + ++count; + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* p) + { + ::new (p) T; + } + + //***************************************************************************** + /// Default contruct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + typename etl::enable_if::value, void>::type + uninitialized_default_construct(T* p, TCounter& count) + { + ::new (p) T; + ++count; + } + //***************************************************************************** /// Default initialises a range of objects to uninitialised memory. ///\ingroup memory @@ -359,6 +403,48 @@ namespace etl return o_end; } + //***************************************************************************** + /// Value construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p) + { + ::new (p) T(); + } + + //***************************************************************************** + /// Value construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, TCounter& count) + { + ::new (p) T(); + ++count; + } + + //***************************************************************************** + /// Copy construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, const T& value) + { + ::new (p) T(value); + } + + //***************************************************************************** + /// Copy construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline void uninitialized_value_construct(T* p, const T& value, TCounter& count) + { + ::new (p) T(value); + ++count; + } + //***************************************************************************** /// Default initialises a range of objects to uninitialised memory. ///\ingroup memory @@ -521,8 +607,9 @@ namespace etl { etl::destroy_at(etl::addressof(*i_begin)); ++i_begin; - --count; } + + count -= std::distance(i_begin, i_end); } //*****************************************************************************