Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-06-28 12:41:31


On Wed, 28 Jun 2006 18:12:21 +0300, "Peter Dimov" <pdimov_at_[hidden]>
wrote:

>Gennaro Prota wrote:
>
>> Sure that's easy for monodimensional arrays. When you write something
>> like, for instance,
>>
>> COUNT_OF_N(3, x)
>
>Out of curiosity, have you ever needed this?

Shall I be sincere? No, I've never needed this :) But I generally
invent a solution... then someone else comes out with the problem for
it! Seriously, I feel it would be a bit inelegant on our part to just
provide for the monodimensional case. Just my groundless impression
perhaps...

>I use the one-dimensional
>function all the time, but I've never, ever, needed to obtain "the 3rd
>size".

In all honesty, I think I've never really used statically sized arrays
with more than 3 dimensions either (by the way, they tend to
immediately grow out of stack possibilities; something like int
x[3][4][5][6][7][8] would already take (8!)/(2!)*sizeof(int) bytes,
thus typically 78.75 KiB, and the single dimension counts here are
very low compared to what one could imagine for a "real life"
application)

>By the way, Microsoft seems to be pushing _countof( x ) as a name for this
>functionality, probably with the intention to make it countof if it gets in
>an official C or C++ document one day. I've always used array_size or just
>size, but countof isn't bad.

I've always chosen a name containing "count" rather than "size"
because "size" implies or may imply "number of bytes", instead of
"number of elements". _countof is nice but should be generalized,
IMHO, even if multidimensional static arrays are rare. And I'd like
for it to also work with tr1::array.

--Gennaro.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk