Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There is another interesting feature in C++17 for lambdas:

Possibility to cast a lambda to a function pointer.

It will become possible to store a lambda as a struct/member that could bind to "this" (like in Javascript).



I assume this is only for stateless lambdas, that have not captured anything? Because otherwise a function pointer would not be enough, right?

Currently, any stateless lambda can decompose into a function pointer and be passed to any function that expects a function pointer, right?

Are you saying that ++17 has augmented this, and if so can you provide more details or a reference (or an example) as I'm quite curious to know more.


https://isocpp.org/files/papers/p0018r3.html

It's the best reference I found. The paper only talks of capturing "*this" by value (as in the original post of the topic).

I think I read that in a draft about coroutines. The idea was to capture "this" by reference and convert the lambda to a function pointer to make it movable.

It would useful for delegates or signals too.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: