
Gennaro Prota <gennaro_prota@yahoo.com> writes:
On Sat, 31 Jan 2004 09:12:58 -0700, "Jonathan Turkanis" <technews@kangaroologic.com> wrote:
Well, I can't really argue with that.
Maybe that's up to me :) There are really cases where you want the compiler to count the elements for you (initialization with the [] = {...} syntax) and retrieve that number *later*.
Yep, this is the key use-case.
PS: Of course I'm not saying one has to use a template for this; I guess most people would consider the sizeof/sizeof technique safe enough (chances that you use a pointer instead of an array are quite low). But, anyway... :)
There is still potential for problems: void f(int x[25]) { for (int i = 0; i < sizeof(x)/sizeof(*x); ++i) { ... } } Don't forget how often the code of experts is copy/pasted by novices ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com