There is a whole library around this and similar techniques in Boost.   I&#x27;ve used it before on several occasions. It&#x27;s quite nice, although it somewhat lays a trap, in the sense that CPP really should be your metaprogramming technique of last (or second-to-last) resort, so it remaining difficult keeps your incentives in line. :)<p>I&#x27;ve never used Chaos PP (the predecessor of Boost.Preprocessor), but IIRC, it enables even more cool stuff at the cost of reduced portability (Boost.Preprocessor contains all the hacks to work on broken preprocessors, while I think Chaos takes more of a &quot;fix your preprocessor&quot; approach).<p><a href="http:&#x2F;&#x2F;www.boost.org&#x2F;doc&#x2F;libs&#x2F;1_59_0&#x2F;libs&#x2F;preprocessor&#x2F;doc&#x2F;index.html" rel="nofollow">http:&#x2F;&#x2F;www.boost.org&#x2F;doc&#x2F;libs&#x2F;1_59_0&#x2F;libs&#x2F;preprocessor&#x2F;doc&#x2F;i...</a>