X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FPreprocessor.h;h=525527ff7adc4b582e54127bac53233ec37303f2;hb=5d8ea9825a6580771e240d093878736bd6e305f6;hp=d0ff34036355378fe0ca4ace00021e46a978ab84;hpb=27494a20393fa45072e7d526d358835f3abe312a;p=folly.git diff --git a/folly/Preprocessor.h b/folly/Preprocessor.h index d0ff3403..525527ff 100644 --- a/folly/Preprocessor.h +++ b/folly/Preprocessor.h @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2016 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,22 @@ // @author: Andrei Alexandrescu -#ifndef FOLLY_PREPROCESSOR_ -#define FOLLY_PREPROCESSOR_ +#pragma once /** * 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. */ -#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__ /** @@ -42,10 +45,38 @@ * number of arguments. If only one argument is given, it returns * that. */ +#ifdef _MSC_VER +// GCC refuses to expand this correctly if this macro itself was +// called with FB_VA_GLUE :( +#define FB_ARG_2_OR_1(...) \ + FB_VA_GLUE(FB_ARG_2_OR_1_IMPL, (__VA_ARGS__, __VA_ARGS__)) +#else #define FB_ARG_2_OR_1(...) FB_ARG_2_OR_1_IMPL(__VA_ARGS__, __VA_ARGS__) +#endif // 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__ + +/** + * Helper macro that just ignores its parameters. + */ +#define FOLLY_IGNORE(...) + +/** + * Helper macro that just ignores its parameters and inserts a semicolon. + */ +#define FOLLY_SEMICOLON(...) ; + /** * FB_ANONYMOUS_VARIABLE(str) introduces an identifier starting with * str and ending with a number that varies with the line. @@ -61,10 +92,7 @@ #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 - - -#endif // FOLLY_PREPROCESSOR_ +#define FB_STRINGIZE(x) #x