C ++模板预处理器工具 [英] C++ Template preprocessor tool

查看:117
本文介绍了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 ++,但不支持模板。我希望我可以写模板,甚至简单的像整数或bool只有参数,并有一些工具预先解析文件,并通过并找到使用模板和扩展调用,并给我一个新的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.

即使是非常有限的工具也是有用的,它不需要支持每个模板quirk,甚至支持多个模块或任何东西。

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 ++模板预处理器工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆