Просмотр исходного кода

core:
* added memory.hpp
* added public unfancy function

Michele Caini 4 лет назад
Родитель
Сommit
fc5a529df8
3 измененных файлов с 35 добавлено и 9 удалено
  1. 33 0
      src/entt/core/memory.hpp
  2. 1 9
      src/entt/entity/storage.hpp
  3. 1 0
      src/entt/entt.hpp

+ 33 - 0
src/entt/core/memory.hpp

@@ -0,0 +1,33 @@
+#ifndef ENTT_CORE_MEMORY_HPP
+#define ENTT_CORE_MEMORY_HPP
+
+
+#include <memory>
+#include <type_traits>
+#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<typename Type>
+[[nodiscard]] constexpr auto * unfancy(Type ptr) ENTT_NOEXCEPT {
+    if constexpr(std::is_pointer_v<Type>) {
+        return ptr;
+    } else {
+        return std::addressof(*ptr);
+    }
+}
+
+
+}
+
+
+#endif

+ 1 - 9
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<Entity, typename std::allocator_tra
         }
     }
 
-    Type * unfancy(alloc_pointer ptr) const {
-        if constexpr(std::is_pointer_v<alloc_pointer>) {
-            return ptr;
-        } else {
-            return std::addressof(*ptr);
-        }
-    }
-
     template<typename... Args>
     void construct(alloc_pointer ptr, Args &&... args) {
         if constexpr(std::is_aggregate_v<value_type>) {

+ 1 - 0
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"