TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

67 点作者 signa11大约 1 个月前

11 条评论

GrantMoyer大约 1 个月前
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).
tempodox大约 1 个月前
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 未加载
hsfzxjy大约 1 个月前
Looks cursed to me.<p>But TIL dollar sign $ is also valid character for identifiers.
评论 #43663855 未加载
notpushkin大约 1 个月前
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 未加载
porridgeraisin大约 1 个月前
That&#x27;s horrifying
评论 #43663351 未加载
foxhill大约 1 个月前
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.
gnulinux大约 1 个月前
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.
mcdeltat大约 1 个月前
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.
pjmlp大约 1 个月前
I fail to see the benefit from the lens of C++23.
pwdisswordfishz大约 1 个月前
Isn’t this basically the obsolete Boost.Lambda?
评论 #43666366 未加载
nialv7大约 1 个月前
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>