TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

67 pointsby signa11about 1 month ago

11 comments

GrantMoyerabout 1 month ago
Another idea in this vein, but with a surprisingly straightforward implementation (27 lines): <a href="https:&#x2F;&#x2F;github.com&#x2F;GrantMoyer&#x2F;lambda_hpp">https:&#x2F;&#x2F;github.com&#x2F;GrantMoyer&#x2F;lambda_hpp</a><p>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&#x27;t decide if it&#x27;s cursed or genuinely useful (minus the unicode name, that&#x27;s cursed).
tempodoxabout 1 month ago
As if C++ didn&#x27;t have enough of “black magic” already, there&#x27;s another layer of that. Just in case you find error messages involving template applications still too readable.
评论 #43667313 未加载
hsfzxjyabout 1 month ago
Looks cursed to me.<p>But TIL dollar sign $ is also valid character for identifiers.
评论 #43663855 未加载
notpushkinabout 1 month ago
Neat. Reminds me of <a href="https:&#x2F;&#x2F;github.com&#x2F;dry-python&#x2F;lambdas">https:&#x2F;&#x2F;github.com&#x2F;dry-python&#x2F;lambdas</a>
评论 #43663778 未加载
porridgeraisinabout 1 month ago
That&#x27;s horrifying
评论 #43663351 未加载
foxhillabout 1 month ago
huh. very cute. in the past, i had an idea for terser lambda syntax, similar to C#&#x27;s expression body functions - which i did end up implementing in clang:<p><pre><code> auto sum = [](auto a, auto b): a+b; </code></pre> but this is something else. i didn&#x27;t think i&#x27;d like it at first, but actually i think i might be coming around to it. the.. dollar syntax is regrettable, although it&#x27;s not a show stopper.
gnulinuxabout 1 month ago
I&#x27;m sorry I know this is horrific but I still love it. This looks like a better version of Boost Lambda2. I would potentially maybe replace `$` with `_` before using this (which should be easy as a layer) like Boost::Lambda2 but otherwise I&#x27;m excited to use it. Not that I would use anything like this in production, but it looks too fun not to play around with.
mcdeltatabout 1 month ago
Pretty cool. I was wondering what kind of arcane magic they used to get $xxx working, since $ is not a standard identifier char... then I realised they straight up define $arg, $call, etc as constants (makes a lot of sense). And $ really is not an identifier char by the Standard, but evidently some compilers accept it.
pjmlpabout 1 month ago
I fail to see the benefit from the lens of C++23.
pwdisswordfishzabout 1 month ago
Isn’t this basically the obsolete Boost.Lambda?
评论 #43666366 未加载
nialv7about 1 month ago
Not really a new idea. These are expression templates: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expression_templates" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expression_templates</a>