Here are two lines I saw in OpenCV
#define CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
#define CV_VA_NUM_ARGS(...) CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
I guess it is to count the number of variadic arguments passing to CV_VA_NUM_ARGS
. Take following code for example:
CV_VA_NUM_ARGS(a,b,c)
will be extended to
CV_VA_NUM_ARGS_HELPER(a,b,c,10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
At this point, I am stuck on understanding what is going on. Concretely, I don't know the utility of _1
,_2
,etc. Can anyone help me out? Here is a similar post while more complex to me.
EDIT:
When I pass no arguments(say CV_VA_NUM_ARGS_HELPER()
), the macro will be replaced by 1 instead of 0, why is that?