
On 9/9/2013 4:44 PM, Brent Lewis wrote:
Currently,
BOOST_VARIADIC_SIZE()
evaluates to 1. Based on http://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/ it can be improved to return 0 for an empty argument list.
The flaw in the detection of empty arguments in the above link has already been discussed. I am not putting down that implementation in saying so. It is impossible to perfectly detect an empty argument. IMO the best case for detecting an empty argument was an example by Paul Mensonides on the web which I adapted for my VMD library at https://github.com/eldiener/variadic_macro_data.git. Furthermore as Paul has pointed out even an "empty" argument is considered an argument and still counts as 1 for the variadic size. In fact the spec for a variadic macro says that you cannot pass no argument when the macro expects variadic data. In other words: #define AVAR(ARG,...) AVAR(something) is an error, but of course AVAR(something,) or #define AVARAG(...) AVARAG() is perfectly fine since you are indeed passing an argument even if it is an "empty" argument.