【发布时间】:2013-03-30 12:42:41
【问题描述】:
我看到std::async指定如下:
template <class F, class... Args> // copied out of the standard
future<typename result_of<F(Args...)>::type>
async(F&& f, Args&&... args);
我原以为它会这样声明:
template <class F, class... Args>
auto async(F&& f, Args&&... args) ->
future<decltype(forward<F>(f)(forward<Args>(args)...)>;
这是否是等效的,或者是否有某种方式可以使用result_of 比使用decltype 更可取? (我知道result_of 适用于类型,而decltype 适用于表达式。)
【问题讨论】:
-
它是指定还是实现
result_of?因为这可能只是实现它的人的心血来潮,或者它可能在decltype进入目标编译器之前就已经实现了。在 Apple 的 libc++ 中,两者都不使用。 -
@zneak:我展示的声明是从标准中复制出来的,所以
std::async是通过result_of指定的。实现可以为所欲为,只要它们提供的行为与指定的相同。