为什么在模板参数上使用velltype?
struct main_executor_type {
using result_type = void;
template <typename F>
void operator()(F f) const {
using f_t = decltype(f);
dispatch_async_f(dispatch_get_main_queue(), new f_t(std::move(f)), [](void* f_) {
auto f = static_cast<f_t*>(f_);
(*f)();
delete f;
});
}
};
exltype(f)
的重点,为什么不简单地使用 f
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于这是由于某些情况会导致
f
和decltype(f)
之间的效果不同。例如,可以将
f
明确指定为数组或功能类型,并且功能参数的类型将调整为指针。然后f
和exttype(f)
给出不同的结果。It depends, since there're some cases leading to different effect between
F
anddecltype(f)
.For example,
F
could be specified explicitly as array or function type, and the type of function parameter will be adjusted to pointer. ThenF
anddecltype(f)
give different result.我看不到此特定代码示例的任何有用的方案(如果我错了,请纠正我),但是如果将参数声明为CV qualified,例如。然后,
使用f_t = exttype(f);
将评估const f
,而使用f_t = f;
将删除简历预选赛并评估至f
。考虑以下简约示例以更好地理解:
I cannot see any useful scenario for this particular code example (please correct me if I'm wrong), but it would look differently if the parameter would have been declared as cv-qualified, e.g.
const F f
. Then,using f_t = decltype(f);
would evaluate toconst F
, whileusing f_t = F;
would remove cv qualifiers and evaluate toF
.Consider the following minimalistic example for better understanding: