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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Type for Overload Set

13 点作者 aw162110711 个月前

3 条评论

captainmuon11 个月前
I&#x27;m really surprised that the first example doesn&#x27;t work. I would have thought that it decides which overload to use only when instantiating the template, and then doing argument dependent lookup (or whatever it is called) to pick the correct overload to match the type of the elements.<p>On the other hand, I don&#x27;t even know how transform is defined. C++ has nothing exactly like IEnumerable&lt;T&gt;, so maybe it is hard to refer to the T? And of course what the article references, that there is no way to refer to the overload set.<p>I usually like C++, but it is not fun when the abstractions break like that.
评论 #40878123 未加载
mmaniac11 个月前
&gt; The crux of the problem, where all the examples above share in common, is that C++ does not have a type for overload sets.<p>&gt;There is a recent proposal that aims to address this exact issue: P3312 - Overload Set Types.<p>Painfully common story.
Trung024611 个月前
This is my own version of `OVERLOAD` that works with both, although I forgot how did it works:<p><pre><code> #define FWD(...) ::std::forward&lt;decltype(__VA_ARGS__)&gt;(__VA_ARGS__) #define LIFT_CUSTOM(X, CAPTURE) CAPTURE (auto &amp;&amp;... args) \ noexcept(noexcept(X(FWD(args)...))) -&gt; decltype((X(FWD(args)...))) { \ return X(FWD(args)...); \ } #define LIFT(X) LIFT_CUSTOM(X, [&amp;])</code></pre>