折叠表达式:解析器堆栈溢出
Fold Expression: parser stackoverflow
嗨,我想,
运算符使用折叠表达式,但 MSVC 一直用 C1026->程序让我烦恼。我将问题分解为最小示例:
#include <utility>
#include <iostream>
template<size_t idx>
void foo()
{
//do some stuff
}
template<typename Ts>
struct ApplySomeFun;
template<size_t... Ts >
struct ApplySomeFun<std::index_sequence<Ts...>>
{
static void execute()
{
(void(foo<Ts>()), ...);// C1026
}
};
int main()
{
ApplySomeFun<std::make_index_sequence<1024>>::execute();
}
这适用于 gcc,但不适用于 msvc。所以我的问题是如何在 msvc 中构建它并保持折叠表达式的清晰度。
这是我的工作轮(感谢 max66 的提示(。
template<size_t idx>
void foo()
{
std::cout << idx << std::endl;
}
template<typename Ts>
struct ApplySomeFun;
template<size_t... Ts >
struct ApplySomeFun<std::index_sequence<Ts...>>
{
static void execute()
{
int unused[] = { 0, ((void)foo<Ts>(), 0)... };//Expander trick
(void)unused; // blocks warnings
}
};
int main()
{
ApplySomeFun<std::make_index_sequence<1024>>::execute();
}
虽然不那么好,但效果很好。
相关文章:
- 在 leetcode 上提交解决方案时出现堆栈缓冲区溢出错误
- 我的 int main() 中出现堆栈溢出错误
- C++ 对象数组堆栈溢出
- 有没有一种方法可以捕获进程中的堆栈溢出?C++Linux
- 对象接收堆栈溢出异常 c++ 的排序向量
- 将公共递归转换为尾递归,因为大型输入的堆栈溢出
- C++ 中递归期间的堆栈溢出
- 启动 dll 时 C# 环境堆栈溢出
- 在C++中使用数组时如何防止堆栈溢出?
- 如何修复递归函数导致的堆栈溢出错误?C++
- 当我尝试为结构分配新指针时出现堆栈溢出错误
- 为什么析构函数无休止地调用自己(导致堆栈溢出)?
- 为什么堆栈溢出?如有建议,不胜感激
- 主函数执行时C++堆栈溢出异常
- 如何在不导致堆栈溢出的情况下计算非常大的数字和很小的 HCF.我正在使用欧几里得算法
- 我正在尝试使用回溯来解决 N queen 问题,但在编译时它会给出运行时错误(动态堆栈缓冲区溢出)
- 如何在Windows上报告堆栈缓冲区溢出
- 如何抑制来自 gcc 中地址清理器的堆栈缓冲区溢出
- 声明大数组时堆栈/堆溢出
- c++中栈溢出和分段错误的危险