Home » Community » U++ community news and announcements » 2023.2
Re: 2023.2 [message #60305 is a reply to message #60304] |
Wed, 15 November 2023 10:41   |
 |
mirek
Messages: 14265 Registered: November 2005
|
Ultimate Member |
|
|
koldo wrote on Wed, 15 November 2023 08:38Hi Mirek
These sentences are very interesting.
Quote:Also, make sure that all other timer (and GUI in general) lambdas are with [=]....
You should only use [&] if you are sure that lambda is invoked immediately (e.g. with CoDo).
I almost understand why you say that but, for didactic reasons, could you explain why to include capture by value rather than by reference.
struct MyApp ... {
Button btn;
String a;
...
};
void MyApp::MyApp()
{
String b;
btn << [&] { a = b; };
}
This creates a dangling reference to b. In fact, if the lambda execution is not 'immediate' (before next statement basically), in most of GUI cases it makes only sense to work with member variables (e.g. 'a' in this case). But then, [=] in fact captures 'this' and that is likely MORE efficient than capturing all member variables individually.
Note that capturing this by [=] was deemed confusing by C++ comitee and they tried to improve on it with [=, this], unfortunately currently it is hard to make code compatible both ways.
Mirek
[Updated on: Wed, 15 November 2023 11:04] Report message to a moderator
|
|
|
 |
|
2023.2
By: mirek on Tue, 24 October 2023 11:17
|
 |
|
Re: 2023.2
By: Tom1 on Tue, 24 October 2023 14:27
|
 |
 |
Re: 2023.2
|
 |
|
Re: 2023.2
By: zsolt on Tue, 24 October 2023 23:19
|
 |
|
Re: 2023.2
By: Klugier on Wed, 25 October 2023 00:00
|
 |
|
Re: 2023.2
|
 |
|
Re: 2023.2
By: mirek on Wed, 25 October 2023 09:47
|
 |
|
Re: 2023.2
By: Tom1 on Tue, 14 November 2023 15:30
|
 |
|
Re: 2023.2
By: mirek on Tue, 14 November 2023 15:48
|
 |
|
Re: 2023.2
By: Tom1 on Tue, 14 November 2023 16:00
|
 |
|
Re: 2023.2
By: Tom1 on Tue, 14 November 2023 16:07
|
 |
|
Re: 2023.2
By: mirek on Tue, 14 November 2023 17:17
|
 |
|
Re: 2023.2
By: Tom1 on Tue, 14 November 2023 17:49
|
 |
|
Re: 2023.2
By: mirek on Tue, 14 November 2023 23:48
|
 |
|
Re: 2023.2
By: koldo on Wed, 15 November 2023 08:38
|
 |
|
Re: 2023.2
By: mirek on Wed, 15 November 2023 10:41
|
 |
|
Re: 2023.2
By: koldo on Thu, 16 November 2023 13:03
|
 |
|
Re: 2023.2
By: Tom1 on Wed, 15 November 2023 11:14
|
 |
|
Re: 2023.2
By: mirek on Wed, 15 November 2023 12:17
|
 |
|
Re: 2023.2
By: Tom1 on Wed, 15 November 2023 13:07
|
Goto Forum:
Current Time: Sun Jul 06 11:58:32 CEST 2025
Total time taken to generate the page: 0.03897 seconds
|