Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-04-12 20:58:53


Peter Dimov wrote:
> > 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;
> };

Well, with a few simplifications, the above could be easily adopted as an
MPL 'count_if' algorithm implementation. In the toy world :). Just a few
points:

1) The above doesn't work on compilers without partial specialization.
2) There are cases when the above doesn't work on Metrowerks Codewarrior
(all versions).
3) When the predicate is complex, the above doesn't work on large sequences
(> 50) because of the limits on the nested template instantiation depth
(some of the compilers don't have a direct (or any) mechanism of increasing
the limit).
4) The above looses the opportunity to cut down compilation time on large
sequences.
5) (IMO) The above is too low-level, and harder to parse and understand when
the original 'fold' version.

Aleksey


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