Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++20] Apply concepts to thread_management.h. #14938

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 deletions include/deal.II/base/thread_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include <utility>
#include <vector>

#ifdef DEAL_II_HAVE_CXX20
# include <concepts>
#endif


#ifdef DEAL_II_WITH_TBB
# include <tbb/task_group.h>
#endif
Expand Down Expand Up @@ -787,8 +792,8 @@ namespace Threads
* @ingroup CPP11
*/
template <typename FunctionObjectType>
DEAL_II_DEPRECATED inline auto
new_thread(FunctionObjectType function_object)
DEAL_II_CXX20_REQUIRES((std::invocable<FunctionObjectType>))
DEAL_II_DEPRECATED inline auto new_thread(FunctionObjectType function_object)
-> Thread<decltype(function_object())>
{
// See the comment in the first new_thread() implementation
Expand Down Expand Up @@ -913,8 +918,10 @@ namespace Threads
* Set the value of a std::promise object by evaluating the action.
*/
template <typename RT, typename Function>
void
evaluate_and_set_promise(Function &function, std::promise<RT> &promise)
DEAL_II_CXX20_REQUIRES(
(std::invocable<Function> &&
std::convertible_to<std::invoke_result_t<Function>, RT>))
void evaluate_and_set_promise(Function &function, std::promise<RT> &promise)
{
promise.set_value(function());
}
Expand All @@ -928,8 +935,9 @@ namespace Threads
* call `std::promise::set_value()` without argument.
*/
template <typename Function>
void
evaluate_and_set_promise(Function &function, std::promise<void> &promise)
DEAL_II_CXX20_REQUIRES((std::invocable<Function>))
void evaluate_and_set_promise(Function & function,
std::promise<void> &promise)
{
function();
promise.set_value();
Expand Down Expand Up @@ -1560,8 +1568,8 @@ namespace Threads
* @ingroup CPP11
*/
template <typename FunctionObjectType>
inline auto
new_task(FunctionObjectType function_object)
DEAL_II_CXX20_REQUIRES((std::invocable<FunctionObjectType>))
inline auto new_task(FunctionObjectType function_object)
-> Task<decltype(function_object())>
{
using return_type = decltype(function_object());
Expand Down