Skip to content(if available)orjump to list(if available)

C++: terser (shorter) lambda == SHORTY (ab-use?)

tempodox

As if C++ didn't have enough of “black magic” already, there's another layer of that. Just in case you find error messages involving template applications still too readable.

GrantMoyer

Another idea in this vein, but with a surprisingly straightforward implementation (27 lines): https://github.com/GrantMoyer/lambda_hpp

I started out trying to write something like the OP, but changed direction when I convinced myself there would have been no sane way to implement member call syntax. I honestly can't decide if it's cursed or genuinely useful (minus the unicode name, that's cursed).

hsfzxjy

Looks cursed to me.

But TIL dollar sign $ is also valid character for identifiers.

tempodox

> $ is also valid character for identifiers.

Has been like that in C since forever.

skullt

It's a common extension but it's not standard. Both C23 and C++23 only allow identifiers to start with a Unicode XID_START character, which excludes $. And with older standards, it was just Latin letters, the underscore, and explicit \u escapes.

If you look in the project's pedantic.cmake, you'll find a add_c_and_cxx_compile_options("-Wno-dollar-in-identifier-extension") just to suppress warnings about this.

null

[deleted]

foxhill

huh. very cute. in the past, i had an idea for terser lambda syntax, similar to C#'s expression body functions - which i did end up implementing in clang:

    auto sum = [](auto a, auto b): a+b;
but this is something else. i didn't think i'd like it at first, but actually i think i might be coming around to it. the.. dollar syntax is regrettable, although it's not a show stopper.

notpushkin

andrepd

I've always thought this should be first-class syntax in any language with lambdas

porridgeraisin

That's horrifying

mbel

To be honest the implementation looks surprisingly readable… at least compared to other horrors like the standard library implementation.

While there are some new rules regarding arguments naming, the new syntax doesn’t feel more complex than the default lambda syntax.

So all in all I would say the most horrifying thing here is the fact that the language allows such extensions in the first place ;)

pjmlp

I fail to see the benefit from the lens of C++23.

nialv7

Not really a new idea. These are expression templates: https://en.wikipedia.org/wiki/Expression_templates

pwdisswordfishz

Isn’t this basically the obsolete Boost.Lambda?

beojan

It's like Boost Lambda2 or Boost HOF. Boost Hana also has a similar feature.

This seems to be more fully featured than all of those though. Maybe some could be ported over to Lambda2.

szundi

[dead]