meta: added entt::resolve_if

This commit is contained in:
Michele Caini
2020-04-20 23:25:10 +02:00
parent d8393dace6
commit 9faf306d1e
2 changed files with 15 additions and 0 deletions

View File

@@ -845,6 +845,20 @@ inline meta_type resolve() ENTT_NOEXCEPT {
}
/**
* @brief Returns the first meta type that satisfies specific criteria, if any.
* @tparam Func Type of the unary predicate to use to test the meta types.
* @param func Unary predicate which returns true for the required element.
* @return The first meta type satisfying the condition, if any.
*/
template<typename Func>
inline meta_type resolve_if(Func func) ENTT_NOEXCEPT {
return internal::find_if([&func](const auto *curr) {
return func(meta_type{curr});
}, *internal::meta_context::global);
}
/**
* @brief Returns the meta type associated with a given identifier.
* @param id Unique identifier.

View File

@@ -289,6 +289,7 @@ struct Meta: ::testing::Test {
TEST_F(Meta, Resolve) {
ASSERT_EQ(entt::resolve<derived_type>(), entt::resolve("derived"_hs));
ASSERT_EQ(entt::resolve_if([](auto type) { return type.id() == "char"_hs; }), entt::resolve<char>());
bool found = false;