On 26/08/2010 19.57, Alf P. Steinbach /Usenet wrote:
> * Richard, on 26.08.2010 19:50:
>> [Please do not mail me a copy of your followup]
>>
>> James Kanze<> spake the secret code
>> <ee08eb9a-8287-41f8-95cb-> thusly:
>>
>>> Still, [C arrays are] for special uses (most of mine are const); for
>>> general work, std::vector is the choice, even if you're not
>>> going to be adjusting the size once it has been constructed.
>>
>> Agreed.
>>
>>>> sizeof() is what you want to tell you the size of a fixed-size
>>>> array, i.e. sizeof(array_)/sizeof(array_[0])
>>>
>>> For that, I use the template function size (which will cause
>>> a compiler error, rather than a wrong value, if invoked on
>>> a pointer.
>>
>> Is this your own recipe, or is it in std or boost?
>
> It's a set of related functions, and they're not in std or boost.
>
> Not sure but I think first designed by Dietmar Kuhl.
I think I learned it from some of his code, too. IIRC that was
around 1999 (big caveat: I don't have a good memory

) and it
was the version that allows getting a compile-time constant
(returning a reference to an array, and to be used in
conjunction with sizeof --and never defined).
In my code, I decided to give up on the constant expression
requirement:
<http://breeze.svn.sourceforge.net/viewvc/breeze/trunk/breeze/counting/>
and I know that James does the same. Of course in C++0x you
could add a constexpr.
At a point, I even wrote a version that gives a constant
expression and also works for multi-dimensional arrays (gives
the count of any projection). And I even managed to make it work
with VC++6

But, of course, there's a difference between
experiments and production code (something that Boost should
definitely learn).
--
Gennaro Prota | I'm available for your projects.
Breeze (preview): <https://sourceforge.net/projects/breeze/>