Tue 15 Mar 2016 04:30:57 PM UTC, original submission:
As a preface: I recognize that what I outline below could be done in other ways with existing make syntax. I'm not interested in suggestions for alternative ways to get similar results.
I had a situation arise a few weeks ago where I had wanted to be able to do macro overloading.
I was experimenting with adding support for namespace-scoped variables.
I had originally written it as one function (each namespace was registered to the same function) but its execution time was rather high. I tested its expansion time with another macro I wrote for repeatedly expanding expressions to see the avg/std of the expansion time.
I had thought the problem might be the conditional logic. As a test I broke it up into separate macros with different names and it improved performance by an order of magnitude, but it was syntactically awkward because I needed a separate macro name for listing, setting, and getting as opposed to the more concise example below.
I'm using C++14 with gnu extensions for my plugin, but the syntax should make it obvious what I'm doing. Here's a sketch of what I had going:
... where it could be used like this:
|