diff --git a/src/memory.h b/src/memory.h index 1920f0b2..6af5d1c5 100644 --- a/src/memory.h +++ b/src/memory.h @@ -425,6 +425,75 @@ namespace etl ++count; } + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_default_at(T* p) + { + ::new (p) T(); + return *reinterpret_cast(p); + } + + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_default_at(T* p, TCounter& count) + { + ::new (p) T(); + ++count; + return *reinterpret_cast(p); + } + + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_copy_at(T* p, const T& other) + { + ::new (p) T(other); + return *reinterpret_cast(p); + } + + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_copy_at(T* p, const T& other, TCounter& count) + { + ::new (p) T(other); + ++count; + return *reinterpret_cast(p); + } + + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_value_at(T* p, const TParameter& value) + { + ::new (p) T(value); + return *reinterpret_cast(p); + } + + //***************************************************************************** + /// Construct an item at address p. + ///\ingroup memory + //***************************************************************************** + template + inline T& make_value_at(T* p, const TParameter& value, TCounter& count) + { + ::new (p) T(value); + ++count; + return *reinterpret_cast(p); + } + //***************************************************************************** /// Default initialises a range of objects to uninitialised memory. ///\ingroup memory @@ -682,6 +751,20 @@ namespace etl new (p) T(static_cast(*this)); ++count; } + + T& make_copy_at(void* p) + { + new (p) T(static_cast(*this)); + return *reinterpret_cast(p); + } + + template + T& make_copy_at(void* p, TCounter& count) + { + new (p) T(static_cast(*this)); + ++count; + return *reinterpret_cast(p); + } }; }