评估参数包
Evaluating a parameter pack
这是不使用折叠来计算参数包的唯一方法吗(因为它需要使用运算符(?
#include <iostream>
template<int ...Is, typename Function>
void eval(Function&& f)
{
// (f(Is)...);
auto op = [&f](int i){f(i); return 0;};
auto doNothing = [](auto...){};
doNothing(op(Is)...);
}
int main()
{
eval<0,1,2>([](int x){std::cout << x << "n";});
}
本质上我想做(f(Is)...)
,但由于某种原因,这在C++是不允许的。有没有比使用上面介绍的解决方法更优雅的方法来实现这一点?
有一个更简单的解决方案:
#include <iostream>
template<int ...Is, typename Function>
void eval(Function&& f)
{
(f(Is),...);
}
int main()
{
eval<0,1,2>([](int x){std::cout << x << "n";});
}
相关文章:
- 懒惰的参数评估try_emplace?
- 如何使用 std::forward 精确地评估参数包的扩展?
- 评估参数包
- 在处理之前评估宏参数
- 函数参数计算顺序与 Lambda 捕获评估顺序
- 为什么不能订购函数参数评估
- 评估虚拟堆栈中的可变参数
- C2064:术语未评估为1个参数qtConcurrent :: map的函数
- 在评估不同参数的constexpr函数时,运行时差异
- 在模板参数中评估 constexpr 时 SFINAE 失败
- 完美转发常量参数以进行持续评估
- 未评估上下文中的默认模板参数和 lambda:错误还是功能?
- 构造std ::配对时,评估参数
- std :: initializer_list:错误c2064:项未评估为0参数的函数
- 单步执行函数,但不进入VS2017的参数评估
- 模板参数评估
- 有没有办法只评估对元组的参数
- 评估采用函数参数的元功能,干燥,而无需使用宏
- 函数参数评估顺序
- "IF"参数评估顺序?