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<T>(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
This commit is contained in:
parent
faa0d3e211
commit
2d7137e776
2 changed files with 16 additions and 19 deletions
|
|
@ -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<typename...INVO, size_t...idx>
|
||||
static auto
|
||||
buildLauncher_impl (tuple<INVO...>&& argCopy, index_sequence<idx...>)
|
||||
{
|
||||
return [invocation = move(argCopy)]
|
||||
(ThreadLifecycle& wrapper)
|
||||
{
|
||||
ASSERT (not wrapper.isLive());
|
||||
wrapper.threadImpl_
|
||||
= std::thread{&ThreadLifecycle::invokeThreadFunction<INVO...>
|
||||
, &wrapper
|
||||
, move(std::get<idx> (invocation))... };
|
||||
};
|
||||
}
|
||||
|
||||
template<class...INVO>
|
||||
static auto
|
||||
buildLauncher (INVO&& ...args)
|
||||
{
|
||||
// materialise functor and arguments as copy, to be handed over into the new thread
|
||||
return buildLauncher_impl (tuple<decay_t<INVO>...>{forward<INVO> (args)...}
|
||||
,index_sequence_for<INVO...>{});
|
||||
tuple<decay_t<INVO>...> argCopy{forward<INVO> (args)...};
|
||||
return [invocation = move(argCopy)]
|
||||
(ThreadLifecycle& wrapper)
|
||||
{
|
||||
auto threadArgs = tuple_cat (tuple{&ThreadLifecycle::invokeThreadFunction<INVO...>, &wrapper}
|
||||
,move (invocation));
|
||||
ASSERT (not wrapper.isLive());
|
||||
wrapper.threadImpl_
|
||||
= make_from_tuple<std::thread> (threadArgs);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65803,6 +65803,10 @@
|
|||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1696812791066" ID="ID_1789709297" MODIFIED="1696812798545" TEXT="Code sinnvoll anordnen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1696813183208" ID="ID_100161158" MODIFIED="1696813227123" TEXT="jetzt noch die invokeThreadFunctor-Memberfunktion mit in das Tupel packen..."/>
|
||||
<node CREATED="1696813171800" ID="ID_155742882" MODIFIED="1696813229500" TEXT="Ha! std::make_from_tuple">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue