Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #123449
| From | ram@zedat.fu-berlin.de (Stefan Ram) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: C/C++ timeline (was Re: Python: A Little Trick For Every Need) |
| Date | 2026-02-06 20:01 +0000 |
| Organization | Stefan Ram |
| Message-ID | <lambdas-20260206204630@ram.dialup.fu-berlin.de> (permalink) |
| References | (20 earlier) <20260205080604.00002be0@gmail.com> <muk2ilFk2oiU4@mid.individual.net> <20260205095745.0000319c@gmail.com> <mul811Fput0U2@mid.individual.net> <20260206112850.00006164@gmail.com> |
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);
}
});
}
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
Re: C/C++ timeline (was Re: Python: A Little Trick For Every Need) ram@zedat.fu-berlin.de (Stefan Ram) - 2026-02-06 20:01 +0000 Re: C/C++ timeline (was Re: Python: A Little Trick For Every Need) Bonita Montero <Bonita.Montero@gmail.com> - 2026-02-07 08:27 +0100
csiph-web