-
Notifications
You must be signed in to change notification settings - Fork 7
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
Allow std::string_view
like behaviour for temporary lambda captures
#12
Comments
The parameter was taken as After making the above change, I suggest trying this: g_store.AddCallback({std23::nontype<&AppMain::OnCallback>, this}); If you store a vector of |
Makes sense. Thanks for the explanation 👍🏼 |
One more question. If I now try to use
Is that also ' correct' (aka as designed, it should not work on member functions)? With that in mind, would this comment from SO still apply to |
Your W.r.t.
If you're only calling a function soon in the scope where the function is taken as a parameter, forwarding reference provides more reasonable codegen compared to |
Hi I was trying out this library but I ran into a problem.
Maybe it's just me not understanding the intended use case or maybe there's something else going wrong.
I tried to use
std::function_ref
as a drop-in replacement for parameters that used to be template args.The code below shows a simplified version of what I attempted to do:
This isn't a 100% replicate-able example, but I hope it does suffice.
So the issue is that the first callback in the

AppMain()
constructor has a 'corrupted'this
pointer.(Note: I placed a breakpoint before the callback was added to capture the address of the
AppMain
class to display that it has not moved)The second callback works fine.

If I understand lambdas correctly, I assume what happens here is that the compiler generated lambda captured data storage is deleted before the callback is invoked. Is this just a bug or is the way I implemented it simply incorrect?
The text was updated successfully, but these errors were encountered: