From b35521dfcbe71d82f9ee969732b21bb7208d3859 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 21 Apr 2020 18:32:35 +0200 Subject: [PATCH] meta: deprecated resolve by id, added entt::resolve_id --- docs/md/meta.md | 13 ++++++------- src/entt/meta/factory.hpp | 15 ++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/md/meta.md b/docs/md/meta.md index 69fc688f1..6b69e591a 100644 --- a/docs/md/meta.md +++ b/docs/md/meta.md @@ -260,19 +260,18 @@ All this has the great merit that, unlike the vast majority of the things present in this library and closely linked to the compile-time, the reflection system stands in fact as a non-intrusive tool for the runtime. -To search for a reflected type there are two options: by type or by _name_. In -both cases, the search can be done by means of the `resolve` function: +To search for a reflected type there are a few options: ```cpp -// search for a reflected type by type +// direct access to a reflected type auto by_type = entt::resolve(); -// search for a reflected type by name -auto by_name = entt::resolve("reflected_type"_hs); +// search for a reflected type by identifier +auto by_id = entt::resolve_id("reflected_type"_hs); ``` -There exits also a third overload of the `resolve` function to use to iterate -all the reflected types at once: +There exits also an overload of the `resolve` function to use to iterate all the +reflected types at once: ```cpp resolve([](auto type) { diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index a51af1d18..fae16aa05 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -860,14 +860,19 @@ inline meta_type resolve_if(Func func) ENTT_NOEXCEPT { /** - * @brief Returns the meta type associated with a given identifier. + * @brief Returns the meta type associated with a given identifier, if any. * @param id Unique identifier. - * @return The meta type associated with the given id, if any. + * @return The meta type associated with the given identifier, if any. */ +inline meta_type resolve_id(const id_type id) ENTT_NOEXCEPT { + return resolve_if([id](const auto type) { return type.id() == id; }); +} + + +/*! @copydoc resolve_id */ +[[deprecated("use entt::resolve_id instead")]] inline meta_type resolve(const id_type id) ENTT_NOEXCEPT { - return internal::find_if([id](const auto *curr) { - return curr->id == id; - }, *internal::meta_context::global); + return resolve_id(id); }