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 » Developing U++ » U++ Developers corner » lambda troubles...
lambda troubles... [message #46869] Sat, 03 September 2016 11:14 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hi,

I am still having some issues with lambda integration and I am interested in community opinion about this...

The whole trouble is caused by two factors:

a) C++11 lambdas have 'unknown type'. That is why they have to be captured by 'catch all' constructor in std::function/Upp::Function

b) U++ originally used operator<<= overload for both Value assignment to widgets and Callback assignments.

So I have quickly learned hard way that it is not possible to use lambdas 'directly' like that lambda is directly assigned to Callback, e.g.:

Button b;
b <<= [=] { Foo(); };


because if things are overloaded for this, then catch-all constructor for lambda activates also for

EditString e;
e <<= "foo";


So, I had to make Callback and Function separate and instead introduced operator<< which 'adds lambda to callback'. Adding is in most cases better anyway.

Button b;
b << [=] { .... };


This really is quite nice, until I have found that it makes it a little bit harder to assign lambda to multiple targets. Originally this worked:

EditString a, b, c;
a <<= b <<= c <<= Sync();


but this is nonsense:

EditString a, b, c;
a << b << c << [=] { Sync(); };


(not that I have not done this mistake...)

while it is possible to write it this way:

EditString a, b, c;
a <<= b <<= c << [=] { Sync(); };


I do not like that very much. I am now thinking if this could be improved somehow... (frankly, it is possibly the last thing I would like to resolve in the new Core). One possible solution is to establish another operator for assigning lambda:

EditString a, b, c;
a ^= b ^= c ^= [=] { Sync(); };


which would either was plain assignment or 'add lambda and return it'.

Maybe it would be also possible to use '>>'

[=] { Sync(); } >> a >> b >> c;


but I guess it looks to weird... Smile

Any thoughts?

[Updated on: Sat, 03 September 2016 11:16]

Report message to a moderator

Re: lambda troubles... [message #46967 is a reply to message #46869] Tue, 04 October 2016 10:29 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, it has lead to this:

http://www.ultimatepp.org/forums/index.php?t=msg&goto=46 966&#msg_46966
Previous Topic: Parser error: Unterminated string
Next Topic: Error C2280 with MSC15 and Uniq
Goto Forum:
  


Current Time: Thu Mar 28 22:22:09 CET 2024

Total time taken to generate the page: 0.01300 seconds