From ccb2bd7f03f95356ceaf569349e4f1d77aae2264 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Fri, 22 Jul 2016 10:15:29 -0700 Subject: [PATCH] Update FB_ONE_OR_NONE in Preproc.h to work with MSVC Summary: There was an MSVC section, but it's much simpler to just use the glue to solve the issue instead. Reviewed By: yfeldblum Differential Revision: D3601184 fbshipit-source-id: f95bd3dfc4b244e1bce21997f44de2970575ad7f --- folly/Preprocessor.h | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/folly/Preprocessor.h b/folly/Preprocessor.h index 800608d4..525527ff 100644 --- a/folly/Preprocessor.h +++ b/folly/Preprocessor.h @@ -22,33 +22,17 @@ * Necessarily evil preprocessor-related amenities. */ +// MSVC's preprocessor is a pain, so we have to +// forcefully expand the VA args in some places. +#define FB_VA_GLUE(a, b) a b + /** * FB_ONE_OR_NONE(hello, world) expands to hello and * FB_ONE_OR_NONE(hello) expands to nothing. This macro is used to * insert or eliminate text based on the presence of another argument. */ -#ifdef _MSC_VER - -#define VA_NARGS_IMPL(_1, _2, _3, _4, _5, N, ...) N -#define VA_NARGS(...) VA_NARGS_IMPL(X,##__VA_ARGS__, 4, 3, 2, 1, 0) -#define VARARG_IMPL2(base, count, ...) base##count(__VA_ARGS__) -#define VARARG_IMPL(base, count, ...) VARARG_IMPL2(base, count, __VA_ARGS__) -#define VARARG(base, ...) VARARG_IMPL(base, VA_NARGS(__VA_ARGS__), __VA_ARGS__) - -#define FB_ONE_OR_NONE0() /* */ -#define FB_ONE_OR_NONE1(x) /* */ -#define FB_ONE_OR_NONE2(x, y) x -#define FB_ONE_OR_NONE3(x, y, z) x -#define FB_ONE_OR_NONE(...) VARARG(FB_ONE_OR_NONE, __VA_ARGS__) - -#else -#define FB_ONE_OR_NONE(a, ...) FB_THIRD(a, ## __VA_ARGS__, a) +#define FB_ONE_OR_NONE(a, ...) FB_VA_GLUE(FB_THIRD, (a, ## __VA_ARGS__, a)) #define FB_THIRD(a, b, ...) __VA_ARGS__ -#endif - -// MSVC's preprocessor is a pain, so we have to -// forcefully expand the VA args in some places. -#define FB_VA_GLUE(a, b) a b /** * Helper macro that extracts the first argument out of a list of any -- 2.34.1