sách gpt4 ăn đã đi

c++ - 在完美转发中 `decltype(std::forward(args))...` 和 Args&& 有什么区别

In lại 作者:太空狗 更新时间:2023-10-29 20:23:38 30 4
mua khóa gpt4 giày nike

今天我在学习完美转发,我创建了这个代码示例

#include 
#include

template
auto toStdFun(Function&& fun, Args&&...args)
{
using retType = decltype(fun(std::forward(args)...));

return std::function<>(args))...)>(fun);

}

int chính()
{
toStdFun([] () {});

}

然后,有人告诉我使用 decltype(std::forward(args))...可以简单地表示为 Args&&...Như thế này:

#include 
#include

template
auto toStdFun(Function&& fun, Args&&...args)
{
using retType = decltype(fun(std::forward(args)...));

return std::function(fun);

}

int chính()
{
toStdFun([] () {});

}

这两个样本有什么区别?

câu trả lời hay nhất

std::forward无非就是添加 &&đi vào T并在用于转发参数时应用引用折叠规则。 Args&&...也是如此

恕我直言,decltype(std::forward(args))...Args&&...是一样的。

关于c++ - 在完美转发中 `decltype(std::forward(args))...` 和 Args&& 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32018519/

30 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress