|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-06-25 07:35:59
Kostya Altukhov wrote:
>
> Daniel Frey wrote:
>
> >template< typename T, size_t N >
> >const char (&sizer(const T(&)[N]))[N];
> >
> You need to remove 'const' here. Then it obviously will not
> work for types, but the following snippet works fine with
> gcc 3.0.2, gcc 2.95.2, and online comeau:
Meanwhile I was pointed to Dietmar's header array_traits.hpp and
personally, I'm quiet satified with the implementation we have now -
although it requires a bit more typing, it seems more natural to me
(given __typeof is available). But without typeof, we could add
namespace boost {
namespace array {
// Declaration only
template< typename T, size_t N > const char
(&static_size(T(&)[N]))[N];
}
}
and use
V2 = sizeof( boost::array::static_size( x ) )
but leave V1 as it is. Probably the name should be better...
Both can live side by side, although I'd prefer to have 'typeof'.
> For typedefs such as "typedef int X[42];", a non-portable line that
> works with mentioned compilers is "V1 = sizeof( sizer(*(X*)1 ))",
> though I would not advise anybody to use that :-)
We better forget that, right? ;)
Regards, Daniel
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk