Remix.run Logo
viega 5 hours ago

That's just:

``` #define MACRO(...) F(__VA_ARGS__); G(__VA_ARGS__) ```

The technique in the article is more often used to type check the individual parameters, or wrap a function call around them individually, etc.

hyperhello 5 hours ago | parent [-]

Ok. How about into F(a,”a”);F(b,”b”);etc.

The problem being automating enums and their names in one call. Like MACRO(a,b,c) and getting a map from a to “a”.

viega 5 hours ago | parent [-]

100%, that's definitely easy to do once you understand the technique.

hyperhello 5 hours ago | parent [-]

Please?

viega 5 hours ago | parent | next [-]

I'm on my phone, but if you start with the top 8 lines in the code box under the ascii art, you'll get an implementation of `H4X0R_MAP()`; the bottom two lines are an example, and you can just write yourself a body that produces one term. Only thing you need to know beyond that is the stringify operator.

viega 5 hours ago | parent | prev [-]

And I should say, if you want to apply the same transformation to arguments twice, but call F() separately from G() per your starting example, you'd just apply your map twice in your top-level macro.

WalterBright 4 hours ago | parent [-]

> if you want to apply the same transformation to arguments twice, but call F() > separately from G() per your starting example, you'd just apply your map twice in your top-level macro

My brain just blew a fuse.