Why cpp std::function can hold capture-lambda, while function pointer cannot?
I've got this code snippet: int x = 3; auto fauto = [=](){ cout<<'x'; }; function<void()> func{fauto}; func(); void (*rawPf)() = fauto; // fail to compile rawPf(); I knew the syntax that only non-capture lambda can be assigned to function pointer. But: Why can std::function hold capture-lambda? as both std::function and function pointers are callable, what's the core difference that makes std::function able to hold capture-lambda, while function pointer cannot? Any detailed explanation on language design for this?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.