Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 15 November 2023 08:38
Hi 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

 
Read Message
Read Message
Read Message icon14.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Ide: branch now displayed in editor bar
Next Topic: TheIDE and U++ have been released on Flathub
Goto Forum:
  


Current Time: Sun Jul 06 11:58:32 CEST 2025

Total time taken to generate the page: 0.03897 seconds