C++ Template preprocessor tool(C++ 模板预处理器工具)
问题描述
是否有编译器或独立的预处理器接收 C++ 文件并运行模板扩展传递,生成具有扩展模板实例化的新 C++ 代码?
Is there a compiler or standalone preprocessor which takes C++ files and runs a template expansion pass, generating new C++ code with expanded template instantiations?
我记得 90 年代中期这样的工具,当时模板还是新的和实验性的,预处理器是一种在没有原生模板支持的情况下使用编译器进行模板编程的方法.
I remember such a tool in the mid-90s when templates were still new and experimental, and the preprocessor was a way to do template programming with compilers without native template support.
这比宏处理步骤复杂得多,因为它可能需要解析和标记代码才能理解上下文.
This is a lot more complicated than a macro-processing step since it would likely require parsing and tokenizing the code to understand the contexts.
我希望在编写 OpenCL 代码时使用这样的工具.OpenCL 是 C++,但不支持模板.我希望我可以编写模板,甚至是简单的模板,例如仅带有整数或布尔参数的模板,并使用一些工具预解析文件并通过查找模板的使用并扩展调用并为我提供新的 C++ 代码OpenCL 编译器可以理解.
My hope is to use such a tool when writing OpenCL code. OpenCL is C++, but does not support templates. I'm hoping I can write templates, even simple ones like with integer or bool only arguments, and have some tool pre-parse the file and go through and find the use of the templates and expand the invocations and give me new C++ code that the OpenCL compiler can understand.
即使是一个非常有限的工具也可能有用,它不需要支持每个模板怪癖,甚至也不需要支持多个模块或任何东西.
Even a very limited tool could be useful, it does not need to support every template quirk, nor even support multiple modules or anything.
替代方案:#define 宏无处不在.. 更丑陋、不安全、效率更低、通用性更差.
The alternative: #define macros everywhere.. uglier, unsafe, less efficient, and less versatile.
推荐答案
Comeau C++ 可以编译"C++到 C.这似乎接近您的目标,因为 OpenCL 不支持 C++ –它更接近 C.
Comeau C++ can "compile" C++ to C. This would seem to be close to your goal, as OpenCL does not support C++ – it's much closer to C.
这篇关于C++ 模板预处理器工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 模板预处理器工具
基础教程推荐
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
