diff options
Diffstat (limited to 'backport-include/backport/magic.h')
-rw-r--r-- | backport-include/backport/magic.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/backport-include/backport/magic.h b/backport-include/backport/magic.h new file mode 100644 index 0000000..d7e7cc9 --- /dev/null +++ b/backport-include/backport/magic.h @@ -0,0 +1,16 @@ +/* + * These tricks are taken from + * http://efesx.com/2010/07/17/variadic-macro-to-count-number-of-arguments/ + * and + * http://efesx.com/2010/08/31/overloading-macros/ + */ + +#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 6,5,4,3,2,1) +#define VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,_6,N,...) N + +#define macro_dispatcher(func, ...) \ + macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__)) +#define macro_dispatcher_(func, nargs) \ + macro_dispatcher__(func, nargs) +#define macro_dispatcher__(func, nargs) \ + func ## nargs |