From fc5a529df85f0f9edd2b83fb25bdff3cb3e4ade6 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 20 Aug 2021 00:26:25 +0200 Subject: [PATCH] core: * added memory.hpp * added public unfancy function --- src/entt/core/memory.hpp | 33 +++++++++++++++++++++++++++++++++ src/entt/entity/storage.hpp | 10 +--------- src/entt/entt.hpp | 1 + 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/entt/core/memory.hpp diff --git a/src/entt/core/memory.hpp b/src/entt/core/memory.hpp new file mode 100644 index 000000000..a6280920a --- /dev/null +++ b/src/entt/core/memory.hpp @@ -0,0 +1,33 @@ +#ifndef ENTT_CORE_MEMORY_HPP +#define ENTT_CORE_MEMORY_HPP + + +#include +#include +#include "../config/config.h" + + +namespace entt { + + + +/** + * @brief Unwraps fancy pointers, does nothing otherwise. + * @tparam Type Pointer type. + * @param ptr A pointer to evaluate. + * @return A plain pointer. + */ +template +[[nodiscard]] constexpr auto * unfancy(Type ptr) ENTT_NOEXCEPT { + if constexpr(std::is_pointer_v) { + return ptr; + } else { + return std::addressof(*ptr); + } +} + + +} + + +#endif diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 6eef1b461..96e92a45e 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -11,7 +11,7 @@ #include "../config/config.h" #include "../core/algorithm.hpp" #include "../core/compressed_pair.hpp" -#include "../core/fwd.hpp" +#include "../core/memory.hpp" #include "../core/type_traits.hpp" #include "../signal/sigh.hpp" #include "component.hpp" @@ -248,14 +248,6 @@ class basic_storage: public basic_sparse_set) { - return ptr; - } else { - return std::addressof(*ptr); - } - } - template void construct(alloc_pointer ptr, Args &&... args) { if constexpr(std::is_aggregate_v) { diff --git a/src/entt/entt.hpp b/src/entt/entt.hpp index c6b96795d..ba3166fac 100644 --- a/src/entt/entt.hpp +++ b/src/entt/entt.hpp @@ -7,6 +7,7 @@ #include "core/family.hpp" #include "core/hashed_string.hpp" #include "core/ident.hpp" +#include "core/memory.hpp" #include "core/monostate.hpp" #include "core/type_info.hpp" #include "core/type_traits.hpp"