|
Boost : |
From: Kostya Altukhov (kostya_at_[hidden])
Date: 2002-06-24 09:09:12
Daniel Frey wrote:
>This allows using sizeof_array safely, as it doesn't compile for
>non-arrays. The only potential drawback I found is, that it's use is a
>bit more complicated for static evaluation and sometimes, you need
>typeof (hopefully in the next standard!?).
>
You can use the following trick:
template<typename T, size_t N>
const char (&sizer(const T (&)[N])) [N];
then the usage is:
double x[] = { 1, 2, 3, 4, 5, 6 };
typedef int[42] X;
enum {
V1 = sizeof(sizer(X)),
V2 = sizeof(sizer(x))
}
No typeof necessary, and doesn't compile for non-arrays.
Best regards,
Kostya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk