Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-12-08 01:40:32


"Reece Dunn" <msclrhd_at_[hidden]> wrote in message
news:BAY7-F8T72YKk6wkgDA00014b6c_at_hotmail.com...

> >the problem is often that you want the size of a variable and not a
> >type, eg,
>
> >sizer( my_array_variable );
>
> >which makes the code look a lot different.
>
> In this case, you need a macro:
>
> #define BOOST_ARRAYSIZE( a ) ( sizeof( a ) / sizeof( a[ 0 ] ))
>
> I can't see any other way of doing this on a variable.

the scheme as done in the old array_traits and as done in collection traits
is something like this:

template< typename T, size_t sz >
give_size<sz> sizer( const (T&)[sz] ); // no definition necessary

and we can use it like

sizeof( sizer( array_var ) );

br

Thorsten


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