Michele Caini 5 лет назад
Родитель
Сommit
9faf306d1e
2 измененных файлов с 15 добавлено и 0 удалено
  1. 14 0
      src/entt/meta/factory.hpp
  2. 1 0
      test/entt/meta/meta.cpp

+ 14 - 0
src/entt/meta/factory.hpp

@@ -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.

+ 1 - 0
test/entt/meta/meta.cpp

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