meta: added entt::resolve_if
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user