From 99621cf08a0c3d3314ae8a4378cbbaefbba653a6 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 20 Aug 2021 15:28:46 +0200 Subject: [PATCH] memory: unfancy -> to_address (waiting for C++20) --- src/entt/core/memory.hpp | 14 +++++++------- src/entt/entity/storage.hpp | 4 ++-- test/entt/core/memory.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/entt/core/memory.hpp b/src/entt/core/memory.hpp index a6280920a..e7b0f48c5 100644 --- a/src/entt/core/memory.hpp +++ b/src/entt/core/memory.hpp @@ -4,25 +4,25 @@ #include #include +#include #include "../config/config.h" namespace entt { - /** - * @brief Unwraps fancy pointers, does nothing otherwise. + * @brief Unwraps fancy pointers, does nothing otherwise (waiting for C++20). * @tparam Type Pointer type. - * @param ptr A pointer to evaluate. - * @return A plain pointer. + * @param ptr Fancy or raw pointer. + * @return A raw pointer that represents the address of the original pointer. */ template -[[nodiscard]] constexpr auto * unfancy(Type ptr) ENTT_NOEXCEPT { - if constexpr(std::is_pointer_v) { +constexpr auto to_address(Type &&ptr) ENTT_NOEXCEPT { + if constexpr(std::is_pointer_v>>) { return ptr; } else { - return std::addressof(*ptr); + return to_address(std::forward(ptr).operator->()); } } diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 96e92a45e..811bd721e 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -251,9 +251,9 @@ class basic_storage: public basic_sparse_set void construct(alloc_pointer ptr, Args &&... args) { if constexpr(std::is_aggregate_v) { - alloc_traits::construct(bucket.first(), unfancy(ptr), Type{std::forward(args)...}); + alloc_traits::construct(bucket.first(), to_address(ptr), Type{std::forward(args)...}); } else { - alloc_traits::construct(bucket.first(), unfancy(ptr), std::forward(args)...); + alloc_traits::construct(bucket.first(), to_address(ptr), std::forward(args)...); } } diff --git a/test/entt/core/memory.cpp b/test/entt/core/memory.cpp index 09f770d45..1c63db2f5 100644 --- a/test/entt/core/memory.cpp +++ b/test/entt/core/memory.cpp @@ -2,10 +2,10 @@ #include #include -TEST(Memory, Unfancy) { +TEST(Memory, ToAddress) { std::shared_ptr shared = std::make_shared(); auto *plain = std::addressof(*shared); - ASSERT_EQ(entt::unfancy(shared), plain); - ASSERT_EQ(entt::unfancy(plain), plain); + ASSERT_EQ(entt::to_address(shared), plain); + ASSERT_EQ(entt::to_address(plain), plain); }