开发者

Add prefix to elements of a variadic macro

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"
funct开发者_运维知识库ion(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!


You could have a look into P99. It uses variadic macros as of C99 for all sorts of code unrolling.


It is scary what you can do with the Boost preprocessor library. It can probably even handle that@!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜