This patch implements an extension to the preprocessor: VA_OPT which expands into its contents if variadic arguments are supplied, or behaves as an empty token if none.
- currently it is only enabled for C++2a (we could always enable this for various other dialects with the appropriate extension or compatibility warnings)
#define F(a,...) a #__VA_OPT__(a ## a) a ## __VA_OPT__(__VA_ARGS__)
A few technicalities (most which were clarified through private correspondence between rsmith, hubert and thomas) are worth mentioning:
- the call F(,) Does not supply any tokens for the variadic arguments and hence VA_OPT behaves as a placeholder
- when expanding VA_OPT (for e.g. F(,1) token pasting occurs eagerly within its contents
- a hash or a hashhash prior to VA_OPT does not inhibit expansion of arguments if they are the first token within VA_OPT.
- essentially, when a variadic argument is supplied, argument substitution occurs within the contents as does stringification and concatenation - and this is substituted, potentially strinigified and concatenated content (but not rescanned) is inserted into the macro expansions token stream just prior to the entire stream being rescanned and concatenated.
See wg21.link/P0306 for further details.
See the example files for more involved examples.
Would greatly appreciate timely feedback =)