The expression "sizeof(Z)/sizeof(Z[0])" in SPAN(Z) is the number of elements in the Z array.
The "(Z)" part of SPAN(Z) is a pointer to the first entry in the Z array and the "((Z)+sizeof(Z)/sizeof(Z[0]))" part points one element past the last entry in the array.
So far this looks complicated but I think it will work even in standard C ( I didn't try it though ).
A pointer will work as an stl iterator so constructing a vector with the two pointers result in the following vector constructor being called:
Code:
template <class InputIterator>
vector(InputIterator, InputIterator)
which results in a vector being created from the objects that the iterators/pointers from the first argument ( inclusive ) to the last argument ( non-inclusive ) point to.
Here's the same thing without the use of the macro and with an intermediate variable which might make things clearer:
Code:
char* pc[] = {"Name", "Last Changed"};
unsigned int pcLen = sizeof(pc)/sizeof(pc[0]); // this evaluates to 2
vector<string> path_column_names(pc, pc+pcLen);
I didn't compile the code in this response so there may be typos.
- Dave