23 Sep
2010
23 Sep
'10
9:31 p.m.
On Thu, Sep 23, 2010 at 02:08, Will Watts <willw@applied.co.uk> wrote:
I am surprised the path class can 'know' the length of a C array. I guess that's the magic of templates for me.
It's actually quite simple: template <typename T, size_t N> size_t array_length(T (&)[N]) { return N; } int a[3]; array_length(a) // returns 3 char *p; array_length(p) // doesn't compile The only trick is the necessity to pass the array by reference, since they can't be passed by value. ~ Scott