Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem occurs when using multiple/nested function pointers and arguments #10

Open
xziyue opened this issue Jul 13, 2017 · 1 comment
Open

Comments

@xziyue
Copy link

xziyue commented Jul 13, 2017

Because my functions do not conform to the required format, I create a helper function to solve this problem, namely

template<typename Fn, typename... Args>
inline void FuncWrapper(int, Fn &&fn, Args&&... args) {
	fn(forward<Args>(args)...);
}

.

That is, if I have a function, e.g.

void print(int num){cout<<num<<endl;}

, I should be able to push it into the thread pool by calling

using task_type = decltype(&print);
auto ptr = &FuncWrapper<task_type,int>;
pool.push(ptr,&print,num);

.

But this simply does not work, for some parts of the code lack the process of coping these arguments and applying "std::forward" to them.

@alexshen
Copy link

alexshen commented Oct 7, 2017

push uses std::bind which will pass stored arguments to ptr as lvalues, but the second and third parameters of ptr are rvalue references, so it won't compile. You can change your ptr to

auto ptr = &FuncWrapper<task_type&, int&>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants