X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FPreprocessor.h;h=c753585424657cccd69cb0dd33f5f9cf2f2c023f;hb=a0359850fd45080ff0862ca0a11884efb424d7d2;hp=20fafabf9000369753312a6853fac00a5eb32da9;hpb=5c77fedbef46995a71ffa268c9fcaf49efddd01b;p=folly.git diff --git a/folly/Preprocessor.h b/folly/Preprocessor.h index 20fafabf..c7535854 100644 --- a/folly/Preprocessor.h +++ b/folly/Preprocessor.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2015 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,24 @@ * 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_THIRD(a, b, ...) __VA_ARGS__ +#endif /** * Helper macro that extracts the first argument out of a list of any @@ -46,6 +62,17 @@ // Support macro for the above #define FB_ARG_2_OR_1_IMPL(a, b, ...) b +/** + * Helper macro that provides a way to pass argument with commas in it to + * some other macro whose syntax doesn't allow using extra parentheses. + * Example: + * + * #define MACRO(type, name) type name + * MACRO(FB_SINGLE_ARG(std::pair), x); + * + */ +#define FB_SINGLE_ARG(...) __VA_ARGS__ + /** * FB_ANONYMOUS_VARIABLE(str) introduces an identifier starting with * str and ending with a number that varies with the line. @@ -61,10 +88,9 @@ #endif /** - * Use FB_STRINGIZE(name) when you'd want to do what #name does inside + * Use FB_STRINGIZE(x) when you'd want to do what #x does inside * another macro expansion. */ -#define FB_STRINGIZE(name) #name - +#define FB_STRINGIZE(x) #x #endif // FOLLY_PREPROCESSOR_