Quellcode durchsuchen

process: process_from utility

Michele Caini vor 8 Monaten
Ursprung
Commit
7b48069bd5
1 geänderte Dateien mit 26 neuen und 0 gelöschten Zeilen
  1. 26 0
      src/entt/process/process.hpp

+ 26 - 0
src/entt/process/process.hpp

@@ -303,6 +303,32 @@ private:
 template<typename Func>
 template<typename Func>
 process_adaptor(Func) -> process_adaptor<nth_argument_t<1u, Func>, Func>;
 process_adaptor(Func) -> process_adaptor<nth_argument_t<1u, Func>, Func>;
 
 
+/**
+ * @brief Utility function to create shared processes from lambdas or functors.
+ * @tparam Func Actual type of process.
+ * @param func Actual process to use under the hood.
+ * @return A properly initialized shared process.
+ */
+template<typename Func>
+auto process_from(Func func) {
+    using type = process_adaptor<nth_argument_t<1u, Func>, Func>;
+    return std::make_shared<type>(std::move(func));
+}
+
+/**
+ * @brief Utility function to create shared processes from lambdas or functors.
+ * @tparam Allocator Type of allocator used to manage memory and elements.
+ * @tparam Func Actual type of process.
+ * @param allocator The allocator to use.
+ * @param func Actual process to use under the hood.
+ * @return A properly initialized shared process.
+ */
+template<typename Allocator, typename Func>
+auto process_from(const Allocator &allocator, Func func) {
+    using type = process_adaptor<nth_argument_t<1u, Func>, Func>;
+    return std::allocate_shared<type>(allocator, std::move(func));
+}
+
 } // namespace entt
 } // namespace entt
 
 
 #endif
 #endif