Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-12-13 16:45:42


----- Original Message -----
From: "David A. Greene" <greened_at_[hidden]>
> >>a framework to allow recursive algorithms should be included.
> >
> > I think a framework to allow recursive algorithms is a subset of the
> > framework in MPL. Basically, you get the "quoted" function object idiom,
and
> > that's it. You can always write your own recursive algorithms with MPL
type
> > lists. The termination are detected slightly differently to allow for
> > different sequences, but that's about it.
>
>
> Can we get examples of this?

I'll defer to Aleksey, since I've forgotten ;-)

> I'm still not clear on what a "quoted"
> function object is.

I think you should forget that term, but what Mat means (and it's Mat's
term, borrowed from lisp) is a class written this way:

struct my_metafunction
{
    template <class Param1, ...class ParamN>
    struct apply
    {
        ... // optional metacomputations here
        typedef type-expression type; // return value
    };
};

A uniform interface to metafunctions makes it possible to re-use them in
different contexts. That's the metafunction formulation used in MPL.

I've left out some details; these can have run-time semantics, too, through
some more standard interface.

> > I did write a number of recursive metafunctions with MPL also, FWIW. It
> > became a last resort, though.
>
> Why? I'm curious. Was it the type of problem you were trying
> to solve?

For one thing, there was more to keep track of. I needed at least two copies
of every function class, one for the regular case, and one for the
termination condition. Other reasons I've already described: the MPL
algorithms do part of the work. Any time somebody does part of the work for
me I have less to think about and less code to write.

> I assume things like GenScatterHierarchy will be provided by a patterns
> or meta-algorithm Boost library. Algorithms are very, very nice,
> but even STL doesn't work for everything.

Right, and it's not supposed to. It provides an extensible framework and
idioms. Some people think of STL as just a collection of examples. I think
it's a bit more useful than that ;-)

> This sounds interesting. Can you give an example? I agree
> that coding a separate termination class can be more difficult
> to read/maintain.

Not right now, but maybe someone else will.

> Yep, I understand what you're saying. Perhaps I am just caught
> up by the fact that typelists are structured with (as I think
> of it) recursive inheritance. It then seems natural to me to
> use recursion to extract the information.

Usually there's no inheritance.
BTW, I'm not saying that recursion isn't a very natural way to approach
typelists. I /am/ saying that if you use recursion, you usually have to do
all the work yourself.

-Dave


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