any: let the wrapper decide what it means to be an owner

This commit is contained in:
Michele Caini
2022-02-09 09:42:49 +01:00
parent 6439dca43a
commit 21ece182f5
2 changed files with 4 additions and 6 deletions

2
TODO
View File

@@ -4,7 +4,6 @@
* add examples (and credits) from @alanjfs :)
WIP:
* any: avoid operations when trivially-*
* runtime events (emitter)
* iterator based try_emplace vs try_insert for perf reasons
* registry: remove reference to basic_sparse_set<E>
@@ -12,7 +11,6 @@ WIP:
* custom allocators all over
WIP:
* customizable any_vtable, sfinae-friendly definition and op::custom for user-def
* resource, forward the id to the loader from the cache and if constexpr the call to load, update doc and describe customization points
* add user data to type_info
* write documentation for custom storages and views!!

View File

@@ -50,7 +50,7 @@ class basic_any {
const Type *element = nullptr;
if constexpr(in_situ<Type>) {
element = (value.mode == policy::owner) ? ENTT_LAUNDER(reinterpret_cast<const Type *>(&value.storage)) : static_cast<const Type *>(value.instance);
element = value.owner() ? ENTT_LAUNDER(reinterpret_cast<const Type *>(&value.storage)) : static_cast<const Type *>(value.instance);
} else {
element = static_cast<const Type *>(value.instance);
}
@@ -63,7 +63,7 @@ class basic_any {
break;
case operation::move:
if constexpr(in_situ<Type>) {
if(value.mode == policy::owner) {
if(value.owner()) {
return new(&static_cast<basic_any *>(const_cast<void *>(other))->storage) Type{std::move(*const_cast<Type *>(element))};
}
}
@@ -204,7 +204,7 @@ public:
/*! @brief Frees the internal storage, whatever it means. */
~basic_any() {
if(vtable && mode == policy::owner) {
if(vtable && owner()) {
vtable(operation::destroy, *this, nullptr);
}
}
@@ -337,7 +337,7 @@ public:
/*! @brief Destroys contained object */
void reset() {
if(vtable && mode == policy::owner) {
if(vtable && owner()) {
vtable(operation::destroy, *this, nullptr);
}