Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define VA_NUM_ARGS(...) VA_ARGS_EXIST(__VA_ARGS__) ? VA_NUM_ARGS_(__VA_ARGS__) : 0
- #define VA_NUM_ARGS_(...) (VA_LAST_ARG((__VA_ARGS__, VA_CREATE_ARGS())))
- #define VA_ARGS_EXIST(...) sizeof(VA_STRINGIFY(VA_APPEND(__VA_ARGS__))) != 2 * sizeof(char)
- #define VA_LAST_ARG(tuple) VA_LAST_ARG_ tuple
- #define VA_LAST_ARG_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
- #define VA_CREATE_ARGS() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
- #define VA_STRINGIFY(...) VA_STRINGIFY_(__VA_ARGS__)
- #define VA_STRINGIFY_(...) #__VA_ARGS__
- #define VA_APPEND(...) __VA_ARGS__##1
- int foo = VA_NUM_ARGS(); // -> 0
- int bar = VA_NUM_ARGS(1); // -> 1
- int baz = VA_NUM_ARGS(1, 2, 3) // -> 3
- /* Yep, all works! */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement