Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-06-26 11:26:57


Gennaro Prota <gennaro_prota_at_[hidden]> writes:

> On Sun, 25 Jun 2006 17:43:26 -0400, David Abrahams
> <dave_at_[hidden]> wrote:
>
>>That somersault is easy enough (although I've forgotten what it was
>>exactly, there's an easy workaround).
>
> Indeed I found it at the first try :)
>
> template <std::size_t n>
> struct counter
> {
> enum { n = n }; // yep :)
>
> template <typename t>
> static char(&count(t(*)[n]))[n];
>
> };
>
> #define COUNT_OF(x) \
> (sizeof counter<(sizeof x / sizeof x[0])>::count(&x))
>
> PS: note the enum!

Wow, great! That trick is a new one to me.

...but is learning a new vc6 hack a virtue?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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