3 ms·
so, in c++ you can do initialization of const value via lambda closures that are immediately evaluated: const int a = [=](){ //do stuff here that
by spott 12y ago
so, in c++ you can do initialization of const value via lambda closures that are immediately evaluated:
const int a = [=](){
//do stuff here that returns an int:
if (condition) { return foo(); } else { return bar(); }
}();
Does this idiom work in swift?
- deleted 12y ago[deleted]
- lyinsteve 12y agolet x: String = { if 3 == 4 { return "Hello" } else { return "Goodbye" } }() Although in this case, I'd just use ternary. let x = (3 == 4) ? "Hello" : "Goodbye"