Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-12 07:08:52


From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>
> > 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).

Perhaps, but I'd still expect something like (syntax made up):

template<class First, class Last, class Pred> struct count_if
{
    enum { value = count_if<typename next<First>::type, Last, Pred>::value +
Pred::template apply< typename dereference<First>::type >::type::value };
    typedef ct_value<int, value> type;
};

template<class Last, class Pred> struct count_if<Last, Last, Pred>
{
    enum { value = 0 };
    typedef ct_value<int, value> type;
};


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