From 2d7137e7764ea0b08d48be30a5dea835878cd486 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 9 Oct 2023 03:19:06 +0200 Subject: [PATCH] Library: get rid of the invoker-helper If we package all arguments together into a single tuple, even including the member-function reference and the this-ptr for the invokeThreadFunction(), which is the actual thread-functor, then we can rely on std::make_from_tuple(tuple), which implements precisely the same hand-over via a std::index_sequence, as used by the explicitly coded solution -- getting rid of some highly technical boilerplate --- src/lib/thread.hpp | 31 ++++++++++++------------------- wiki/thinkPad.ichthyo.mm | 4 ++++ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/lib/thread.hpp b/src/lib/thread.hpp index 383bd9d54..11a664d86 100644 --- a/src/lib/thread.hpp +++ b/src/lib/thread.hpp @@ -134,8 +134,8 @@ namespace lib { using std::decay_t; using std::invoke_result_t; using std::is_constructible; - using std::index_sequence_for; - using std::index_sequence; + using std::make_from_tuple; + using std::tuple_cat; using std::is_same; using std::__or_; @@ -344,28 +344,21 @@ namespace lib { - template - static auto - buildLauncher_impl (tuple&& argCopy, index_sequence) - { - return [invocation = move(argCopy)] - (ThreadLifecycle& wrapper) - { - ASSERT (not wrapper.isLive()); - wrapper.threadImpl_ - = std::thread{&ThreadLifecycle::invokeThreadFunction - , &wrapper - , move(std::get (invocation))... }; - }; - } - template static auto buildLauncher (INVO&& ...args) { // materialise functor and arguments as copy, to be handed over into the new thread - return buildLauncher_impl (tuple...>{forward (args)...} - ,index_sequence_for{}); + tuple...> argCopy{forward (args)...}; + return [invocation = move(argCopy)] + (ThreadLifecycle& wrapper) + { + auto threadArgs = tuple_cat (tuple{&ThreadLifecycle::invokeThreadFunction, &wrapper} + ,move (invocation)); + ASSERT (not wrapper.isLive()); + wrapper.threadImpl_ + = make_from_tuple (threadArgs); + }; } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 0ee17066d..a2ffe3593 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -65803,6 +65803,10 @@ + + + +