向可变参数宏的元素添加前缀
我正在研究 将 C++ 转变为 Javascript 和我想编写一个宏 function
来执行以下操作:
function (x, y, z, ...)
to
[=] (var a, var b, var x, var y, var z, ...) -> Object
基本上就是:
function() -> "[=] (var a, var b) -> Object"
function(x) -> "[=] (var a, var b, var x) -> Object"
function(x, y) -> "[=] (var a, var b, var x, var y) -> Object"
...
它不必是可变参数,如果它可以适用于适合我的固定数量的元素。另外,如果需要编译器扩展,我也很乐意使用。
有关信息,我当前的宏如下,
#define function(...) [=] (var a, var b, ##__VA_ARGS__) -> Object
我尝试寻找宏技巧,但找不到符合我需要的东西。
谢谢!
I am working on morphing C++ into Javascript and I would like to write a macro function
that does the following:
function (x, y, z, ...)
to
[=] (var a, var b, var x, var y, var z, ...) -> Object
Basically that would be:
function() -> "[=] (var a, var b) -> Object"
function(x) -> "[=] (var a, var b, var x) -> Object"
function(x, y) -> "[=] (var a, var b, var x, var y) -> Object"
...
It does not have to be variadic, if that can work for a fixed number of elements that works for me. Also if an compiler extension is required, I'm good with it.
For information my current macro is the following
#define function(...) [=] (var a, var b, ##__VA_ARGS__) -> Object
I tried to look for macro tricks but I can't find something that matches what I need.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看P99。从 C99 开始,它使用可变宏来进行各种代码展开。
You could have a look into P99. It uses variadic macros as of C99 for all sorts of code unrolling.
使用 Boost 预处理器 库可以做的事情令人恐惧。它甚至可能可以处理@!
It is scary what you can do with the Boost preprocessor library. It can probably even handle that@!