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 » Callback: C++11 lambda support
Callback: C++11 lambda support [message #42465] Mon, 17 March 2014 19:07 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You can now assign lambda to callback. Have to say, simplifies things quite a lot, no more need to add methods to dialogs...Smile
Re: Callback: C++11 lambda support [message #42536 is a reply to message #42465] Sat, 22 March 2014 13:28 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1076
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Mirek,

For me this is killer feature. Thanks!

Sincerely,
Klugier


U++ - one framework to rule them all.
Re: Callback: C++11 lambda support [message #42665 is a reply to message #42536] Thu, 27 March 2014 22:14 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Mirek,

It looks like the additional features broke some existing code:

I get the following errors when trying to compile docking package:
/home/didier/upp/uppsrc/Docking/DockCont.cpp: In constructor ‘Upp::DockCont::DockCont()’:
/home/didier/upp/uppsrc/Docking/DockCont.cpp:824:23: erreur: no match for ‘operator=’ (operand types are ‘Upp::Callback1<Upp::ValueArray>’ and ‘Upp::Callback1<Upp::Vector<Upp::Value> >’)
  tabbar.WhenCloseSome = THISBACK(TabsClosed);
                       ^
/home/didier/upp/uppsrc/Docking/DockCont.cpp:824:23: note: candidate is:
In file included from /home/didier/upp/uppsrc/Core/Callback.h:6:0,
                 from /home/didier/upp/uppsrc/Core/Core.h:301,
                 from /home/didier/upp/uppsrc/Draw/Draw.h:6,
                 from /home/didier/upp/uppsrc/RichText/RichText.h:4,
                 from /home/didier/upp/uppsrc/CtrlCore/CtrlCore.h:4,
                 from /home/didier/upp/uppsrc/CtrlLib/CtrlLib.h:4,
                 from /home/didier/upp/uppsrc/Docking/Docking.h:4,
                 from /home/didier/upp/uppsrc/Docking/DockWindow.cpp:1,
                 from /home/didier/upp.out/MyApps/Docking/GCC.Blitz.Gui.Mt.Shared/$blitz.cpp:3:
/home/didier/upp/uppsrc/Core/Cbgen.h:117:16: note: Upp::Callback1<P1>& Upp::Callback1<P1>::operator=(const Upp::Callback1<P1>&) [with P1 = Upp::ValueArray]
 Callback1<P1>& Callback1<P1>::operator=(const Callback1& c)
                ^
/home/didier/upp/uppsrc/Core/Cbgen.h:117:16: note:   no known conversion for argument 1 from ‘Upp::Callback1<Upp::Vector<Upp::Value> >’ to ‘const Upp::Callback1<Upp::ValueArray>&’
Re: Callback: C++11 lambda support [message #42666 is a reply to message #42665] Thu, 27 March 2014 22:22 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
In Docking/DockCont.h & .cpp replacing :
void TabsClosed(Vector<Value> vv);

with
void TabsClosed(ValueArray vv);

solves the issue
Re: Callback: C++11 lambda support [message #42725 is a reply to message #42465] Mon, 31 March 2014 13:35 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

Could you put a simple sample of it?


Best regards
Iñaki
Re: Callback: C++11 lambda support [message #42727 is a reply to message #42725] Mon, 31 March 2014 14:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
foo.WhenAction = [$]() { foo <<= (int)~foo + 1; }

Anyway, there is still some work to be done; the main issues are overloading problems. Only Callback::operator= works so far.

The problem is that in order to capture lambda, you have to provide completely 'all-catch' template

template <class T>
void CaptureLambda(T x);

which then is causing overloading problems..

I am almost inclined to add some stronger typing via macro, like

foo <<= lambda() { foo <<= (int)~foo + 1; }

and lambda would provide a case to something more reasonable, like #define lambda (LambdaCallback)[&].
Re: Callback: C++11 lambda support [message #42730 is a reply to message #42727] Mon, 31 March 2014 16:22 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Shocked Smile

Best regards
Iñaki
Re: Callback: C++11 lambda support [message #42875 is a reply to message #42730] Sat, 12 April 2014 19:32 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
After some intial experience, overloading problems proved to be too ugly, so putting lambda into Callback now requires call to "lambda" function or using LAMBDA macro:

Callback1<int> cb = lambda([&](int x) { something(x); });

Callback cb = LAMBDA(int x) { something(x); };
Previous Topic: Testing of migrated and upgraded forum
Next Topic: Development blog canceled, topics moved to "news"
Goto Forum:
  


Current Time: Wed Apr 24 18:53:13 CEST 2024

Total time taken to generate the page: 0.03352 seconds