Skip to content

Commit

Permalink
meta: avoid implicit conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Oct 4, 2024
1 parent 8cfd635 commit 414365c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
20 changes: 10 additions & 10 deletions src/entt/meta/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ struct basic_meta_sequence_container_traits {
* @return An iterator to the first element of the container.
*/
static iterator begin(const meta_ctx &area, void *container, const void *as_const) {
return container ? iterator{area, static_cast<Type *>(container)->begin()}
: iterator{area, static_cast<const Type *>(as_const)->begin()};
return (container != nullptr) ? iterator{area, static_cast<Type *>(container)->begin()}
: iterator{area, static_cast<const Type *>(as_const)->begin()};
}

/**
Expand All @@ -143,8 +143,8 @@ struct basic_meta_sequence_container_traits {
* @return An iterator that is past the last element of the container.
*/
static iterator end(const meta_ctx &area, void *container, const void *as_const) {
return container ? iterator{area, static_cast<Type *>(container)->end()}
: iterator{area, static_cast<const Type *>(as_const)->end()};
return (container != nullptr) ? iterator{area, static_cast<Type *>(container)->end()}
: iterator{area, static_cast<const Type *>(as_const)->end()};
}

/**
Expand All @@ -166,7 +166,7 @@ struct basic_meta_sequence_container_traits {
auto *const non_const = any_cast<typename Type::iterator>(&it.base());
return {area, static_cast<Type *>(container)->insert(
non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base()),
value ? *static_cast<const typename Type::value_type *>(value) : *static_cast<const std::remove_reference_t<typename Type::const_reference> *>(cref))};
(value != nullptr) ? *static_cast<const typename Type::value_type *>(value) : *static_cast<const std::remove_reference_t<typename Type::const_reference> *>(cref))};
}
}

Expand Down Expand Up @@ -245,8 +245,8 @@ struct basic_meta_associative_container_traits {
* @return An iterator to the first element of the container.
*/
static iterator begin(const meta_ctx &area, void *container, const void *as_const) {
return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->begin()}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->begin()};
return (container != nullptr) ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->begin()}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->begin()};
}

/**
Expand All @@ -257,7 +257,7 @@ struct basic_meta_associative_container_traits {
* @return An iterator that is past the last element of the container.
*/
static iterator end(const meta_ctx &area, void *container, const void *as_const) {
return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->end()}
return (container != nullptr)) ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->end()}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->end()};
}

Expand Down Expand Up @@ -295,8 +295,8 @@ struct basic_meta_associative_container_traits {
* @return An iterator to the element with the given key, if any.
*/
static iterator find(const meta_ctx &area, void *container, const void *as_const, const void *key) {
return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->find(*static_cast<const typename Type::key_type *>(key))}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->find(*static_cast<const typename Type::key_type *>(key))};
return (container != nullptr) ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->find(*static_cast<const typename Type::key_type *>(key))}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->find(*static_cast<const typename Type::key_type *>(key))};
}
};

Expand Down
38 changes: 19 additions & 19 deletions src/entt/meta/meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class meta_any {
}

void release() {
if(node.dtor.dtor && (storage.policy() == any_policy::owner)) {
if((node.dtor.dtor != nullptr) && (storage.policy() == any_policy::owner)) {
node.dtor.dtor(storage.data());
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ class meta_any {
meta_any(const meta_ctx &area, const meta_any &other)
: storage{other.storage},
ctx{&area},
node{other.node.resolve ? other.node.resolve(internal::meta_context::from(*ctx)) : other.node},
node{(other.node.resolve != nullptr) ? other.node.resolve(internal::meta_context::from(*ctx)) : other.node},
vtable{other.vtable} {}

/**
Expand All @@ -297,7 +297,7 @@ class meta_any {
meta_any(const meta_ctx &area, meta_any &&other)
: storage{std::move(other.storage)},
ctx{&area},
node{other.node.resolve ? std::exchange(other.node, internal::meta_type_node{}).resolve(internal::meta_context::from(*ctx)) : std::exchange(other.node, internal::meta_type_node{})},
node{(other.node.resolve != nullptr) ? std::exchange(other.node, internal::meta_type_node{}).resolve(internal::meta_context::from(*ctx)) : std::exchange(other.node, internal::meta_type_node{})},
vtable{std::exchange(other.vtable, &basic_vtable<void>)} {}

/**
Expand Down Expand Up @@ -586,7 +586,7 @@ class meta_any {

/*! @copydoc any::operator== */
[[nodiscard]] bool operator==(const meta_any &other) const noexcept {
return (ctx == other.ctx) && ((!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info && storage == other.storage));
return (ctx == other.ctx) && (((node.info == nullptr) && (other.node.info == nullptr)) || ((node.info != nullptr) && (other.node.info != nullptr) && *node.info == *other.node.info && storage == other.storage));
}

/*! @copydoc any::operator!= */
Expand Down Expand Up @@ -1365,7 +1365,7 @@ class meta_type {
* @return The tag for the class template of the underlying type.
*/
[[nodiscard]] inline meta_type template_type() const noexcept {
return node.templ.resolve ? meta_type{*ctx, node.templ.resolve(internal::meta_context::from(*ctx))} : meta_type{};
return (node.templ.resolve != nullptr) ? meta_type{*ctx, node.templ.resolve(internal::meta_context::from(*ctx))} : meta_type{};
}

/**
Expand Down Expand Up @@ -1421,7 +1421,7 @@ class meta_type {
*/
[[nodiscard]] meta_data data(const id_type id) const {
const auto *elem = internal::look_for<&internal::meta_type_descriptor::data>(internal::meta_context::from(*ctx), node, id);
return elem ? meta_data{*ctx, *elem} : meta_data{};
return (elem != nullptr) ? meta_data{*ctx, *elem} : meta_data{};
}

/**
Expand All @@ -1443,7 +1443,7 @@ class meta_type {
*/
[[nodiscard]] meta_func func(const id_type id) const {
const auto *elem = internal::look_for<&internal::meta_type_descriptor::func>(internal::meta_context::from(*ctx), node, id);
return elem ? meta_func{*ctx, *elem} : meta_func{};
return (elem != nullptr) ? meta_func{*ctx, *elem} : meta_func{};
}

/**
Expand All @@ -1459,7 +1459,7 @@ class meta_type {
}
}

if(sz == 0u && node.default_constructor) {
if(sz == 0u && (node.default_constructor != nullptr)) {
return node.default_constructor(*ctx);
}

Expand All @@ -1484,12 +1484,12 @@ class meta_type {
* @return A wrapper that references the given instance.
*/
[[nodiscard]] meta_any from_void(void *elem) const {
return (elem && node.from_void) ? node.from_void(*ctx, elem, nullptr) : meta_any{meta_ctx_arg, *ctx};
return ((elem != nullptr) && node.from_void) ? node.from_void(*ctx, elem, nullptr) : meta_any{meta_ctx_arg, *ctx};
}

/*! @copydoc from_void */
[[nodiscard]] meta_any from_void(const void *elem) const {
return (elem && node.from_void) ? node.from_void(*ctx, nullptr, elem) : meta_any{meta_ctx_arg, *ctx};
return ((elem != nullptr) && node.from_void) ? node.from_void(*ctx, nullptr, elem) : meta_any{meta_ctx_arg, *ctx};
}

/**
Expand All @@ -1503,7 +1503,7 @@ class meta_type {
meta_any invoke(const id_type id, meta_handle instance, meta_any *const args, const size_type sz) const {
if(node.details) {
if(auto *elem = internal::find_member<&internal::meta_func_node::id>(node.details->func, id); elem != nullptr) {
if(const auto *candidate = lookup(args, sz, instance && (instance->data() == nullptr), [curr = elem]() mutable { return curr ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
if(const auto *candidate = lookup(args, sz, instance && (instance->data() == nullptr), [curr = elem]() mutable { return (curr != nullptr) ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
return candidate->invoke(*ctx, meta_handle{*ctx, std::move(instance)}, args);
}
}
Expand Down Expand Up @@ -1574,7 +1574,7 @@ class meta_type {
*/
[[nodiscard]] [[deprecated("use ::custom() instead")]] meta_prop prop(const id_type key) const {
const auto *elem = internal::look_for<&internal::meta_type_descriptor::prop>(internal::meta_context::from(*ctx), node, key);
return elem ? meta_prop{*ctx, *elem} : meta_prop{};
return (elem != nullptr) ? meta_prop{*ctx, *elem} : meta_prop{};
}

/*! @copydoc meta_data::traits */
Expand All @@ -1598,7 +1598,7 @@ class meta_type {

/*! @copydoc meta_prop::operator== */
[[nodiscard]] bool operator==(const meta_type &other) const noexcept {
return (ctx == other.ctx) && ((!node.info && !other.node.info) || (node.info && other.node.info && *node.info == *other.node.info));
return (ctx == other.ctx) && (((node.info == nullptr) && (other.node.info == nullptr)) || ((node.info != nullptr) && (other.node.info != nullptr) && *node.info == *other.node.info));
}

private:
Expand All @@ -1617,7 +1617,7 @@ class meta_type {
}

[[nodiscard]] inline meta_type meta_any::type() const noexcept {
return node.info ? meta_type{*ctx, node} : meta_type{};
return (node.info != nullptr) ? meta_type{*ctx, node} : meta_type{};
}

template<typename... Args>
Expand Down Expand Up @@ -1850,7 +1850,7 @@ class meta_associative_container::meta_iterator final {
* @return The meta value type of the container.
*/
[[nodiscard]] inline meta_type meta_sequence_container::value_type() const noexcept {
return value_type_node ? meta_type{*ctx, value_type_node(internal::meta_context::from(*ctx))} : meta_type{};
return (value_type_node != nullptr) ? meta_type{*ctx, value_type_node(internal::meta_context::from(*ctx))} : meta_type{};
}

/**
Expand Down Expand Up @@ -1952,20 +1952,20 @@ inline meta_sequence_container::iterator meta_sequence_container::erase(const it
* @return The meta key type of the a container.
*/
[[nodiscard]] inline meta_type meta_associative_container::key_type() const noexcept {
return key_type_node ? meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))} : meta_type{};
return (key_type_node != nullptr) ? meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))} : meta_type{};
}

/**
* @brief Returns the meta mapped type of a container.
* @return The meta mapped type of the a container.
*/
[[nodiscard]] inline meta_type meta_associative_container::mapped_type() const noexcept {
return mapped_type_node ? meta_type{*ctx, mapped_type_node(internal::meta_context::from(*ctx))} : meta_type{};
return (mapped_type_node != nullptr) ? meta_type{*ctx, mapped_type_node(internal::meta_context::from(*ctx))} : meta_type{};
}

/*! @copydoc meta_sequence_container::value_type */
[[nodiscard]] inline meta_type meta_associative_container::value_type() const noexcept {
return value_type_node ? meta_type{*ctx, value_type_node(internal::meta_context::from(*ctx))} : meta_type{};
return (value_type_node != nullptr) ? meta_type{*ctx, value_type_node(internal::meta_context::from(*ctx))} : meta_type{};
}

/*! @copydoc meta_sequence_container::size */
Expand Down Expand Up @@ -2001,7 +2001,7 @@ inline bool meta_associative_container::reserve(const size_type sz) {
*/
inline bool meta_associative_container::insert(meta_any key, meta_any value = {}) {
return !const_only && key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))})
&& (!mapped_type_node || value.allow_cast(meta_type{*ctx, mapped_type_node(internal::meta_context::from(*ctx))}))
&& ((mapped_type_node == nullptr) || value.allow_cast(meta_type{*ctx, mapped_type_node(internal::meta_context::from(*ctx))}))
&& insert_fn(const_cast<void *>(data), std::as_const(key).data(), std::as_const(value).data());
}

Expand Down
4 changes: 2 additions & 2 deletions src/entt/meta/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ template<auto Member, typename Type, typename Value>
}

[[nodiscard]] inline auto *find_overload(meta_func_node *curr, std::remove_pointer_t<decltype(meta_func_node::invoke)> *const ref) {
while(curr && (curr->invoke != ref)) { curr = curr->next.get(); }
while((curr != nullptr) && (curr->invoke != ref)) { curr = curr->next.get(); }
return curr;
}

Expand Down Expand Up @@ -208,7 +208,7 @@ template<typename... Args>
}

[[nodiscard]] inline const void *try_cast(const meta_context &context, const meta_type_node &from, const meta_type_node &to, const void *instance) noexcept {
if(from.info && to.info && *from.info == *to.info) {
if((from.info != nullptr) && (to.info != nullptr) && *from.info == *to.info) {
return instance;
}

Expand Down

0 comments on commit 414365c

Please sign in to comment.