From 5e3ff7a57b242a5f98d594c3d6c09375b9651c1f Mon Sep 17 00:00:00 2001 From: Marika Lehmann Date: Tue, 22 Nov 2022 13:29:52 +0100 Subject: [PATCH] iox-#1732 Squash me! Signed-off-by: Marika Lehmann --- .../internal/cxx/storable_function.inl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl index 0dff78d6c2e..694a3e40588 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl @@ -166,14 +166,19 @@ inline void swap(storable_function& f, storable_function +void* allocate(byte_t* startAddress) +{ + uint64_t alignedPosition = cxx::align(reinterpret_cast(startAddress), alignof(T)); + return reinterpret_cast(alignedPosition); +} + template template inline void storable_function>::storeFunctor(const Functor& functor) noexcept { using StoredType = typename std::remove_reference::type; - uint64_t alignedPosition = cxx::align(reinterpret_cast(&m_storage), alignof(StoredType)); - alignedPosition -= reinterpret_cast(&m_storage); - m_callable = static_cast(&m_storage + alignedPosition); + m_callable = allocate(m_storage); // erase the functor type and store as reference to the call in storage new (m_callable) StoredType(functor); @@ -190,9 +195,7 @@ template inline void storable_function>::copy(const storable_function& src, storable_function& dest) noexcept { - uint64_t alignedPosition = cxx::align(reinterpret_cast(&dest.m_storage), alignof(CallableType)); - alignedPosition -= reinterpret_cast(&dest.m_storage); - dest.m_callable = static_cast(&dest.m_storage + alignedPosition); + dest.m_callable = allocate(dest.m_storage); // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable); @@ -210,9 +213,7 @@ inline void storable_function>::move(st storable_function& dest) noexcept { // m_callable = static_cast(align(reinterpret_cast(m_storage), alignof(CallableType))); - uint64_t alignedPosition = cxx::align(reinterpret_cast(&dest.m_storage), alignof(CallableType)); - alignedPosition -= reinterpret_cast(&dest.m_storage); - dest.m_callable = static_cast(&dest.m_storage + alignedPosition); + dest.m_callable = allocate(dest.m_storage); // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable);