|
Boost : |
From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-07-30 21:45:07
----- Original Message -----
From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
To: <boost_at_[hidden]>
Sent: Wednesday, July 31, 2002 2:44 AM
Subject: [boost] dynamic_bitset: performances and other
notes -dyn_bs_modifications #1.zip (0/1)
> Two words on the attached code: as I said the idea (used by STLPort
> too) is to use a table in which the element of index n is the number
> of digits in the binary representation of n.
If you're going to shrink/enlarge the table at compile-time given platform
settings, you may need something like:
template <int N> struct CountBits
{
BOOST_STATIC_CONSTANT(long,
result = CountBits<N/2>::result + (N&1)
);
};
template <> struct CountBits<0>
{
BOOST_STATIC_CONSTANT(long,
result = 0
);
};
and the relative PP magic to fill a compile-time sized table with it (I
still have to look into the PP library, it's still black magic to me). The
template could be unrolled to gain some compile-time speed (very trendy
nowadays it seems ;), but I usually prefer keeping the things very easy and
readable, whenever it's possible.
Giovanni Bajo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk