From: Wolfgang Bangerth Date: Wed, 21 Aug 2024 22:19:46 +0000 (-0600) Subject: Add TaskResult::emplace_object(). X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15aad27f7fee2fcccb8bdb2ca1f70312de4882ab;p=dealii.git Add TaskResult::emplace_object(). --- diff --git a/include/deal.II/base/task_result.h b/include/deal.II/base/task_result.h index f00fc958f8..ce2cce7d89 100644 --- a/include/deal.II/base/task_result.h +++ b/include/deal.II/base/task_result.h @@ -320,6 +320,34 @@ namespace Threads try_emplace_task(const Callable &creator) const DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v)); + /** + * 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 || + std::is_copy_assignable_v)); + + /** + * 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 || + std::is_copy_assignable_v)); + /** * 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 + inline void + TaskResult::emplace_object(const T &t) + DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v || + std::is_copy_assignable_v)) + { + clear(); + task_result = t; + result_is_available = true; + } + + + template + inline void + TaskResult::emplace_object(T &&t) + DEAL_II_CXX20_REQUIRES((std::is_copy_constructible_v || + std::is_copy_assignable_v)) + { + clear(); + task_result = std::move(t); + result_is_available = true; + } + + template inline void TaskResult::clear()