You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to specify in the documentation that, when submitting tasks, arguments are passed by value by default (see std::bind()), which can significantly slow down the pool.
And that one should use std::ref() to pass arguments by reference, such as: auto my_future = pool.submit(task, arg1, std::ref(arg2));
It would be convenient if there was a way for arguments to be passed by reference automatically when the function definition specifies it, but not sure how to do it.
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion! I will incorporate this in the documentation in the next release.
Unfortunately, as far as I know, it's impossible to define submit() or push_task() so that they can accept references automatically. This is because std::function needs the std::ref (or std::cref for constant references) wrappers to be used explicitly in the constructor in order to take arguments that are references. (But if you find a way to bypass that, please let me know!)
It would be useful to specify in the documentation that, when submitting tasks, arguments are passed by value by default (see std::bind()), which can significantly slow down the pool.
And that one should use std::ref() to pass arguments by reference, such as:
auto my_future = pool.submit(task, arg1, std::ref(arg2));
It would be convenient if there was a way for arguments to be passed by reference automatically when the function definition specifies it, but not sure how to do it.
The text was updated successfully, but these errors were encountered: