Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-04-11 18:10:15


Andrei Alexandrescu wrote:
> I don't have access to MPL here, could anyone tell me how I can download
it
> again?

The latest work-in-progress is in the CVS under 'mpl_v2' branch. The current
snapshot of it is available for download from here -
http://groups.yahoo.com/group/boost/files/mpl/.

>
> I forgot what the convention for Predicate was, but I recall it has a
nested
> template class 'apply' that exposes 'value'. Assuming that that's the
case,
> the following code implements count_if, in a slightly terser manner (it
also
> relies on first principles only - there's no core infrastructure to
learn).
> The code maps to the algorithm like this: for a null typelist, count_if is
> zero; for any other typelist, count_if returns an optional one (if the
> predicate is true for the head) plus the result of count_if, applied to
the
> tail of the typelist.
>
> template <class TList, class Predicate> struct count_if;
>
> template <class Predicate>
> struct count_if<Nulltype, Predicate>
> {
> BOOST_STATIC_CONSTANT(
> unsigned long,
> value = 0);
> };
>
>
> template <class H, class T, class Predicate>
> struct count_if<typelist<H, T>, Predicate>
> {
> BOOST_STATIC_CONSTANT(
> unsigned long,
> value = (Predicate::apply<H>::value ? 1 : 0) + count_if<T,
> Predicate>::value);
> };
>

The above implementation is useless for 'tiny_list' (and any type sequence
we use here at work).

Aleksey


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