Possible Duplicate:
How does this “size of array” template function work?
Is there any possibility to implement NARR
without a macro in C++ (C++0x)?
const static pair<string,int> data[] = {
{"Montag",1}, {"Dienstag",2}, {"Mittwoch",3}, {"Donnerstag",4},
{"Freitag",5}, {"Samstag",6}, {"Sonntag",7}
};
#define NARR(A) (sizeof(A)/sizeof(*A))
const static map<string,int> german_weekdays(data, data+NARR(data));
A simple function is not possible, because then the []
loses its size-information and becomes just another poiner:
size_t narr(sometype arr[]) { /* won't work */ }
Templates? Overloading? Magic?