logoalt Hacker News

noselasdlast Sunday at 8:05 PM1 replyview on HN

No, (in C++) the lambda can capture the the variable by value, and the lambda itself can be passed around by value. If you capture a variable by reference or pointer that your lambda outlives, your code got a serious bug.


Replies

gf000last Sunday at 8:34 PM

And in Rust, it will enforce correct usage via the borrow checker - the outlive case simply will not compile.

If you do want it, you have the option to, say, heap allocate.