* added memory.hpp
* added public unfancy function
This commit is contained in:
Michele Caini
2021-08-20 00:26:25 +02:00
parent bc1081550d
commit fc5a529df8
3 changed files with 35 additions and 9 deletions

33
src/entt/core/memory.hpp Normal file
View File

@@ -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

View File

@@ -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>) {

View File

@@ -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"