I'm new to C++, coming recently from Swift. Is there any way to get shorter lambda syntax?
I have a lot of lines like:
columns = {
Col(_("Name"), "string", [] (Person *p) {
return p->Name();
}),
Col(_("Age"), "int", [] (Person *p) {
return p->Age();
}),
Col(_("Bank"), "string", [&banks] (Person *p) {
return banks.lookUp(p->Identifier()).Name;
}),
//..etc..
};
Some of the columns require longer lambdas, but as it is the syntax for writing the lambda is about as long as the content it self.
Can the lambda syntax be reduced at all? (say by implicit argument or implicitly return the last statement)
Eg in Swift I could do something like this and it would be the same:
Col(_("Age"), "int", { $0.Age() }),
EDIT: Added the Bank column as an example of a more complicated one.
Can the lambda syntax be reduced at all?
I don't think so. The essential components of a lambda
function for your needs are:
[ capture-list ] ( params ) { body }
You have it in as minimal a form as is possible with C++11.