(Correction to my original remark: it looks like lambdas didn't make it
into C23 after all...? I confess I lost track of the discussion at the
time, as I haven't needed any new features in the language since C99
added // comments, declare-anywhere, and stdint.h.)
John Ames <commodorejohn@gmail.com> wrote or quoted:
(Correction to my original remark: it looks like lambdas didn't make it
into C23 after all...? I confess I lost track of the discussion at the
time, as I haven't needed any new features in the language since C99
added // comments, declare-anywhere, and stdint.h.)
C++ has had lambdas for ages. Here's a code example from
Sebastian Theophil's Cppcon talk from 2025. (The lambdas
start with the square brackets.)
expected<double, string> parse_and_invert(string_view sv) {
return parse_int(sv).transform(
[](int n) { return n*2; }
).transform_error([](parse_error p) -> string {
switch(p) {
case parse_error::out_of_bounds:
return "out of bounds";
case parse_error::invalid_input:
return "invalid_input";
}
}).and_then(
[](int n) -> std::expected<double, std::string> {
if(0==n) {
return std::unexpected("division by zero");
} else {
return std::expected<double, std::string>(1.0/n);
}
});
}
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 18:04:52 |
| Calls: | 810 |
| Calls today: | 1 |
| Files: | 1,287 |
| D/L today: |
10 files (21,017K bytes) |
| Messages: | 193,396 |