Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-01-10 16:10:19


----- Original Message -----
From: "David Abrahams" <dave_at_[hidden]>

> <snip>
>
> AFAICT from browsing it quickly, the significance of TTP in your code
> is that you are passing templates instead of types as functions in the
> interfaces to your metafunctions, which I think is inadvisable,
> because it eventually breaks metafunction polymorphism.

Not really. That is the purpose of various types of partial binding
constructs. The only real way to break metafunction polymorphism is to use
non-type template arguments in the the template template parameters, and not
even that will totally break it. Strictly not using template template
parameters has its own problems since you can't pass namespaces as
arguments, etc.. This can complicate a design real quick as you make more
and more "indirection" layers:

struct metafunction {
    template<class T> struct actual_metafunction {
        // ...
    };
};

vs.

template<class T> struct metafunction {
    // ...
};

I'm not saying the convention is bad, just that it has its own set of
associated problems.

> Other than that, the final interface you show is one that's acheivable
> without TTP at all.

Yes, you can do it without TTP, but it isn't as clean. (I only had a rough
idea in my head when I made the remark.) You pay a price for the
abstraction that you mention by "metafunction polymorphism." The difference
is that I prefer to do that abstraction external to the core implementation
and provide a bridge layer for common usages. In any case, it turns out to
be slightly longer anyway because I forgot about the need for ::template
when one (or all) of the parameters a dependent. However, I was going for a
general purpose "iterative OR" when I started it, rather than just a
solution to the particular problem. I basically just had a general idea of
something like this:

contains<T>::arg<int>::arg<double>::arg<std::string>::value

...but the "::template" makes it longer:

contains<T>
    ::template arg<int>
    ::template arg<double>
    ::template arg<std::string>
    ::value

Altogether, I'm quite pleased with the mechanism, as I find the linear
typelist implementation "neat," and I've never seen anything like that
implementation. The template classes "fold_left" and "fold_right" are not
even metafunctions in any normal sense. I wouldn't know what to call them!

Paul Mensonides


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