]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add TaskResult::emplace_object().
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Aug 2024 22:19:46 +0000 (16:19 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Aug 2024 22:28:28 +0000 (16:28 -0600)
include/deal.II/base/task_result.h

index f00fc958f8a5e76a0922e4447dae8f9300fa4d79..ce2cce7d8965db0a65b76517b7f96c354defad40 100644 (file)
@@ -320,6 +320,34 @@ namespace Threads
     try_emplace_task(const Callable &creator) const
       DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>));
 
+    /**
+     * Instead of letting a task compute the object stored by this
+     * instance of Lazy, just copy the object passed as an argument
+     * and use it instead.
+     *
+     * As for several other member functions, this function can only be called
+     * if there is not currently a running task whose result is supposed to
+     * be used.
+     */
+    void
+    emplace_object(const T &t)
+      DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v<T> ||
+                              std::is_copy_assignable_v<T>));
+
+    /**
+     * Instead of letting a task compute the object stored by this
+     * instance of Lazy, just move the object passed as an argument
+     * and use it instead.
+     *
+     * As for several other member functions, this function can only be called
+     * if there is not currently a running task whose result is supposed to
+     * be used.
+     */
+    void
+    emplace_object(T &&t)
+      DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v<T> ||
+                              std::is_copy_assignable_v<T>));
+
     /**
      * Reset the current object to a state as if it had been
      * default-constructed. For the same reasons as outlined
@@ -499,6 +527,30 @@ namespace Threads
 
 
 
+  template <typename T>
+  inline void
+  TaskResult<T>::emplace_object(const T &t)
+    DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v<T> ||
+                            std::is_copy_assignable_v<T>))
+  {
+    clear();
+    task_result         = t;
+    result_is_available = true;
+  }
+
+
+  template <typename T>
+  inline void
+  TaskResult<T>::emplace_object(T &&t)
+    DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v<T> ||
+                            std::is_copy_assignable_v<T>))
+  {
+    clear();
+    task_result         = std::move(t);
+    result_is_available = true;
+  }
+
+
   template <typename T>
   inline void
   TaskResult<T>::clear()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.