Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2006-06-25 19:28:19


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!

--Gennaro.


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