|
|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
}
|