Couldn't stop thinking about it and began to play with macros instead. In case of macros, Boost has a cool set of really impressive macros to deliver. However, I didn't want me to spoil all the fun I could have on my own and tried out my own preprocessor-based iterations, loop constructs and so on. In the end, they seem to archieve it similar as C preprocessor macros do basically work with jumps and concatenation. So if you want to write a macro that generates you a sequence of characters, you can only archieve this by defining each loop iteration with a single macro. You'd end up with as many macros as you'd need iteration and then create a macro that concenates the name prefix with the number you've given. As long as you indexed all your macros in an incrementing order, it's maps it's index parameter directly to a macro names. You can essentially do nothing else cause recursion doesn't work here - it's not possible with the way how macros get evaluated in the preprocessor.

That said, you can do the same thing for creating increment and decrement operators. Something like "#INC2 3", "#INC3 4" etc - really atomic stuff you'd usually never bother about. So if you combine this with your loop, you can end with an all-same expression for each iteration and you just need to copy the line and increasing the number for more iterations (as opposed to always concatenating and hardcoding the previous loop iteration). Quite convenient I have to say. And really interesting! If there's incrementing and decrementing, you can also add, substract, divide, multiply etc... I really enjoy this kind of stuff at the moment as it's some fundamental, something that makes you scream "OH GEEZ, IT'S WORKIN" when everything's fine. And as a result, it'll enable to to generate indexed sequences, typedefs etc... As I noticed that I'll need to define a larger amount of only incrementally different template parameters to get an universal module interface done, I had a desire to create functions making sequences of C code. If bears some problems of course. You can't concatenate ",", ";" or "=" for example, those and just not valid or need to included otherwise. It's OK I think, but stuff's getting equally hard to write using cpp macros as I'd write it using templates. However, the preprocessor is the next instance above templates (as templates are the next instance above normal code). Therefore there's no way 'round cpp macros in C++ to actually create real code without optimization on. I'm trying to keep it simple and essential in functionality. Some good chances exist that it can make solve some problems I had before.

No comments: