Home » Community » U++ community news and announcements » Lambda support in MenuBar
Re: Lambda support in MenuBar [message #46611 is a reply to message #46599] |
Sat, 11 June 2016 11:23   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Mirek - Now more serious,
I tried to integrated new lambda callback with ide New file menu - but there is a problem. Here is my new code:
void WorkspaceWork::NewMenu(Bar& bar)
{
bar.Add("File", CtrlImg::File(), THISBACK2(NewPackageFile, "New file", ""));
bar.Add("Separator", THISBACK(AddSeparator))
.Help("Add text separator line");
bar.Separator();
for (int i = 0; i < categories.GetCount(); i++) {
// Lambda in place - as argument
bar.Add(categories.GetKey(i), [&, i](Bar& subBar) {
for (FileType& fileType : categories[i]) {
String name = fileType.GetName();
String extension = fileType.GetExtension();
if (fileType.IsSeparator())
subBar.Separator();
else
subBar.Add(name, fileType.GetImage(), THISBACK2(NewPackageFile, "New " + name, extension));
}
});
}
}
And i have got following compilation issue:
/home/klugier/upp/uppsrc/Core/Callback.h: In instantiation of 'Res Upp::Function<Res(ArgTypes ...)>::Wrapper<F>::Execute(ArgTypes ...) [with F = WorkspaceWork::NewMenu(Upp::Bar&)::<lambda(Upp::Bar&)>; Res = void; ArgTypes = {}]
':
/home/klugier/upp/uppsrc/ide/UppWspc.cpp:1238:1: required from here
/home/klugier/upp/uppsrc/Core/Callback.h:15:60: error: no match for call to '(WorkspaceWork::NewMenu(Upp::Bar&)::<lambda(Upp::Bar&)>) ()'
virtual Res Execute(ArgTypes... args) { return fn(args...); }
^
/home/klugier/upp/uppsrc/ide/UppWspc.cpp:931:51: note: candidate: WorkspaceWork::NewMenu(Upp::Bar&)::<lambda(Upp::Bar&)>
bar.Add(categories.GetKey(i), [&, i](Bar& subBar) {
^
/home/klugier/upp/uppsrc/ide/UppWspc.cpp:931:51: note: candidate expects 1 argument, 0 provided
In file included from /home/klugier/upp/uppsrc/Core/Core.h:293:0,
from /home/klugier/upp/uppsrc/Esc/Esc.h:4,
from /home/klugier/upp/uppsrc/ide/Core/Core.h:4,
from /home/klugier/upp/uppsrc/ide/Common/Common.h:4,
from /home/klugier/upp/uppsrc/ide/ide.h:4,
from /home/klugier/upp/uppsrc/ide/UppWspc.cpp:1:
/home/klugier/upp/uppsrc/Core/Callback.h:15:60: error: return-statement with a value, in function returning 'void' [-fpermissive]
virtual Res Execute(ArgTypes... args) { return fn(args...); }
Is that problem here that bar lambda is created in THISBACK method?
Sincerely,
Klugier
U++ - one framework to rule them all.
|
|
|
Goto Forum:
Current Time: Sat May 03 12:26:46 CEST 2025
Total time taken to generate the page: 0.00966 seconds
|