storage: clean up

This commit is contained in:
Michele Caini
2021-11-24 12:47:27 +01:00
parent 43099f47d0
commit 706bbb83c9

View File

@@ -348,28 +348,14 @@ protected:
* @param entt A valid identifier.
* @param value Optional opaque value.
*/
void try_emplace(const Entity entt, [[maybe_unused]] const void *value) override {
[[maybe_unused]] const auto try_emplace_with_args = [this, entt](auto &&...args) {
const auto pos = base_type::slot();
construct(assure_at_least(pos), std::forward<decltype(args)>(args)...);
ENTT_TRY {
base_type::try_emplace(entt);
ENTT_ASSERT(pos == base_type::index(entt), "Misplaced component");
}
ENTT_CATCH {
std::destroy_at(std::addressof(element_at(pos)));
ENTT_THROW;
}
};
void try_emplace([[maybe_unused]] const Entity entt, const void *value) override {
if(value) {
if constexpr(std::is_copy_constructible_v<value_type>) {
try_emplace_with_args(*static_cast<const value_type *>(value));
emplace(entt, *static_cast<const value_type *>(value));
}
} else {
if constexpr(std::is_default_constructible_v<value_type>) {
try_emplace_with_args();
emplace(entt);
}
}
}