From 691d2b43fa6eed5af1a2ae1d51b4d149eb93bc20 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 28 Sep 2023 17:45:32 +0200 Subject: [PATCH] Library: add shortcut-ctor for own-member function A common usage pattern is to derive from lib::Thread and then implement the actual thread function as a member function of this special-Thread-object (possibly also involving other data members) Provide a simplified invocation for this special case, also generating the thread-id automatically from the arguments --- src/lib/thread.hpp | 8 ++++ tests/library/thread-wrapper-test.cpp | 3 +- wiki/thinkPad.ichthyo.mm | 63 ++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/lib/thread.hpp b/src/lib/thread.hpp index 81821e896..6f3eebd17 100644 --- a/src/lib/thread.hpp +++ b/src/lib/thread.hpp @@ -108,6 +108,7 @@ #include "lib/nocopy.hpp" #include "include/logging.h" #include "lib/meta/function.hpp" +#include "lib/format-util.hpp" #include "lib/result.hpp" #include @@ -302,6 +303,13 @@ namespace lib { , std::forward (args)... } { } + template + ThreadLifecycle (RES (SUB::*memFun) (ARGS...), ARGS&& ...args) + : ThreadLifecycle{util::joinArgList (lib::meta::typeStr(), args...) + ,std::move (memFun) + ,static_cast (this) + ,std::forward (args)... } + { } }; }//(End)base implementation. diff --git a/tests/library/thread-wrapper-test.cpp b/tests/library/thread-wrapper-test.cpp index 9b7dcf2bc..4738526d6 100644 --- a/tests/library/thread-wrapper-test.cpp +++ b/tests/library/thread-wrapper-test.cpp @@ -93,8 +93,7 @@ namespace lib { : Thread { TestThread() - : Thread("test Thread creation", - bind (&TestThread::theOperation, this, checksum.createVal(), checksum.createVal())) + : Thread{&TestThread::theOperation, checksum.createVal(), checksum.createVal()} { } // note the binding (functor object) is passed as anonymous temporary diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 58af91f14..7722990a1 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -79385,7 +79385,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -79394,6 +79394,29 @@ Date:   Thu Apr 20 18:53:17 2023 +0200

+ + + + + + + + + + + + + + + + +

+ das macht nur den Code komplex, macht aber die Diagnostik nicht besser; std::invoke hat bereits gute Diagnostik (man muß sie nur lesen können) +

+ +
+ +
@@ -79841,6 +79864,13 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + @@ -79861,6 +79891,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + @@ -79870,6 +79903,25 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + +

+ ### Lumiera halted due to an unexpected Error ### +

+

+ +

+

+ +++ Caught Exception LUMIERA_ERROR_INVALID:invalid input or parameters +

+ +
+ +
@@ -80231,12 +80283,21 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + +