Last active
December 31, 2015 02:19
-
-
Save qzchenwl/7919792 to your computer and use it in GitHub Desktop.
variable num
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1) | |
#define VA_NUM_ARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, 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 | |
#define VAR1(x) L ## #x" = " << x | |
#define VAR2(x, ...) L ## #x" = " << x << L", " << VAR1(__VA_ARGS__) | |
#define VAR3(x, ...) L ## #x" = " << x << L", " << VAR2(__VA_ARGS__) | |
#define VAR4(x, ...) L ## #x" = " << x << L", " << VAR3(__VA_ARGS__) | |
#define VAR5(x, ...) L ## #x" = " << x << L", " << VAR4(__VA_ARGS__) | |
#define VAR6(x, ...) L ## #x" = " << x << L", " << VAR5(__VA_ARGS__) | |
#define VAR7(x, ...) L ## #x" = " << x << L", " << VAR6(__VA_ARGS__) | |
#define VAR8(x, ...) L ## #x" = " << x << L", " << VAR7(__VA_ARGS__) | |
#define VAR9(x, ...) L ## #x" = " << x << L", " << VAR8(__VA_ARGS__) | |
#define VAR10(x, ...) L ## #x" = " << x << L", " << VAR9(__VA_ARGS__) | |
#define VAR11(x, ...) L ## #x" = " << x << L", " << VAR10(__VA_ARGS__) | |
#define VAR12(x, ...) L ## #x" = " << x << L", " << VAR11(__VA_ARGS__) | |
#define VAR13(x, ...) L ## #x" = " << x << L", " << VAR12(__VA_ARGS__) | |
#define VAR14(x, ...) L ## #x" = " << x << L", " << VAR13(__VA_ARGS__) | |
#define VAR15(x, ...) L ## #x" = " << x << L", " << VAR14(__VA_ARGS__) | |
#define VAR16(x, ...) L ## #x" = " << x << L", " << VAR15(__VA_ARGS__) | |
#define VAR(...) MACRO_DISPATCHER(VAR, __VA_ARGS__) (__VA_ARGS__) | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
char str[] = "hello world"; | |
int val = 42; | |
double val_d = 3.14; | |
bool val_b = true; | |
wcout << VAR(str, val, val_d, val_b) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment