From 456ae3b62e695e615deb851b7dacc9b3ee8b8481 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Tue, 19 Sep 2023 17:32:49 +0100 Subject: [PATCH] refactor(core): use memory::move instead of static_cast --- .../core/reflection/traits/constructible.hpp | 17 +++++++++-------- .../reflection/traits/constructible_utils.hpp | 8 ++++---- .../core/reflection/traits/constructible.cpp | 6 +++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/include/cubos/core/reflection/traits/constructible.hpp b/core/include/cubos/core/reflection/traits/constructible.hpp index 2868c792e..a46fde7da 100644 --- a/core/include/cubos/core/reflection/traits/constructible.hpp +++ b/core/include/cubos/core/reflection/traits/constructible.hpp @@ -6,6 +6,8 @@ #include +#include + namespace cubos::core::reflection { /// @brief Describes how a reflected type may be constructed and destructed. @@ -132,27 +134,26 @@ namespace cubos::core::reflection /// @return Builder. Builder&& withDefaultConstructor() && { - mTrait = static_cast(mTrait).withDefaultConstructor( - [](void* instance) { new (instance) T(); }); - return static_cast(*this); + mTrait = memory::move(mTrait).withDefaultConstructor([](void* instance) { new (instance) T(); }); + return memory::move(*this); } /// @brief Sets the copy constructor of the type. /// @return Builder. Builder&& withCopyConstructor() && { - mTrait = static_cast(mTrait).withCopyConstructor( + mTrait = memory::move(mTrait).withCopyConstructor( [](void* instance, const void* other) { new (instance) T(*static_cast(other)); }); - return static_cast(*this); + return memory::move(*this); } /// @brief Sets the move constructor of the type. /// @return Builder. Builder&& withMoveConstructor() && { - mTrait = static_cast(mTrait).withMoveConstructor( - [](void* instance, void* other) { new (instance) T(static_cast(*static_cast(other))); }); - return static_cast(*this); + mTrait = memory::move(mTrait).withMoveConstructor( + [](void* instance, void* other) { new (instance) T(memory::move(*static_cast(other))); }); + return memory::move(*this); } private: diff --git a/core/include/cubos/core/reflection/traits/constructible_utils.hpp b/core/include/cubos/core/reflection/traits/constructible_utils.hpp index 7b9e9a45c..90e0cd6f5 100644 --- a/core/include/cubos/core/reflection/traits/constructible_utils.hpp +++ b/core/include/cubos/core/reflection/traits/constructible_utils.hpp @@ -24,19 +24,19 @@ namespace cubos::core::reflection if constexpr (std::is_default_constructible::value) { - builder = static_cast&&>(builder).withDefaultConstructor(); + builder = memory::move(builder).withDefaultConstructor(); } if constexpr (std::is_copy_constructible::value) { - builder = static_cast&&>(builder).withCopyConstructor(); + builder = memory::move(builder).withCopyConstructor(); } if constexpr (std::is_move_constructible::value) { - builder = static_cast&&>(builder).withMoveConstructor(); + builder = memory::move(builder).withMoveConstructor(); } - return static_cast&&>(builder).build(); + return memory::move(builder).build(); } } // namespace cubos::core::reflection diff --git a/core/src/cubos/core/reflection/traits/constructible.cpp b/core/src/cubos/core/reflection/traits/constructible.cpp index 5078d368a..17fd8b4ca 100644 --- a/core/src/cubos/core/reflection/traits/constructible.cpp +++ b/core/src/cubos/core/reflection/traits/constructible.cpp @@ -21,21 +21,21 @@ ConstructibleTrait&& ConstructibleTrait::withDefaultConstructor(DefaultConstruct { CUBOS_ASSERT(!mDefaultConstructor, "Default constructor already set"); mDefaultConstructor = defaultConstructor; - return static_cast(*this); + return memory::move(*this); } ConstructibleTrait&& ConstructibleTrait::withCopyConstructor(CopyConstructor copyConstructor) && { CUBOS_ASSERT(!mCopyConstructor, "Copy constructor already set"); mCopyConstructor = copyConstructor; - return static_cast(*this); + return memory::move(*this); } ConstructibleTrait&& ConstructibleTrait::withMoveConstructor(MoveConstructor moveConstructor) && { CUBOS_ASSERT(!mMoveConstructor, "Move constructor already set"); mMoveConstructor = moveConstructor; - return static_cast(*this); + return memory::move(*this); } std::size_t ConstructibleTrait::size() const