Saturday, April 15, 2023

Digest for comp.lang.c++@googlegroups.com - 2 updates in 1 topic

Ben Bacarisse <ben.usenet@bsb.me.uk>: Apr 15 12:27AM +0100

> that you enjoy figuring out this kind of thing, and fun and curiosity are
> perfectly good reasons. But I would like to know if there are any other
> reasons or use-cases for this.
 
I took the name Some_Library_Func as a clue. There is an external
interface (probably in C but maybe not) that requires are "plain"
function pointer argument.
 
--
Ben.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 15 03:50AM +0200

Am 14.04.2023 um 21:15 schrieb Frederick Virchanza Gotham:
 
> I'm not suggesting that a lambda-with-captures should convert implicitly
> to a function pointer, because then we'd have the issue of the lifetime
> of the thunk.
 
You can accees thread-local and static variables from a lambda without
captures. That's useful f.e. if you have a callback for a C-function
where you need a usual function pointer. And imagine you've got sth.
like a function-object for std::sort() having no captures makes this
function object more lightweight since you won't have to copy the
function object across the recursive calls of std::sort.
 
vector<int> vi;
...
thread_local int x;
sort( vi.begin, vi.end(),
[]( int left, int right ) -> bool { left + x < right; } );
 
 
Havinv such a lambda-object without captures gives more performance.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: