cpptime icon indicating copy to clipboard operation
cpptime copied to clipboard

Input arguments to handler

Open hemalbavishi opened this issue 4 years ago • 1 comments

Is it possible to extend the timer functionality to pass input argument((void *)arg) to handler function?

hemalbavishi avatar Jul 17 '20 06:07 hemalbavishi

Hello @hemalbavishi and sorry for the very late reply,

Not sure if you are still interested, but I answer it anyway in case it helps somebody.

The handler function is a std::function. It is therefore possible to use e.g. a lambda and pass additional data to it, either by moving, copying or sharing. The best way to do it depends on the shared data.

I added an example in the tests that shows how to share (by copy) a shared_ptr with a lambda, which is used as the handler function.

eglimi avatar Mar 05 '23 11:03 eglimi