Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-09-19 09:17:46


>From: "Jaap Suter" <J.Suter_at_[hidden]>

> > > For example, why limit this to
> > > only one -type depth? Why not call ::type on the incoming parameters
> until
> > > we reach a type that has a ::value parameter?
> >
> > It's not necessary if all metafunctions does it.

> Once every meta function
> works this way, we could even remove the current mpl::if_ and rename
> mpl::apply_if to mpl::if_ because it works the way we want it.

I've also thought about that. However, mpl::if_ and mpl::apply_if works a
little differently, in that they don't evaluate their _arguments_ (except
that it could evaluate the condition, applying "::type" to it). Instead,
they evaluate the selected argument, based on the condition, or not
(apply_if and if_, respectively).

Thus, they are more like "pass-through" functions, in that they don't need
to evaluate the then- and else-part, to work. It's enough to evaluate the
condition.

They may be likened to the ?: operator. Consider:

int value=condition ? <expression1> : <expression2>;

Here, ?: doesn't evaluate <expression1> or <expression2>; it just "passes it
through" to the "value=..." statement, which then evaluates it.

With the system that the metafunctions evaluate their own arguments, I've
actually had less use for apply_if, and have instead been able to use if_,
because apply_if is just a way to combine an if_ and an evaluation of the
result. However, if the result of the if_ is evaluated in the next step,
anyway, it's not needed. :)

For example, the "factorial" metafunction I gave in the previous posting
could have used if_, instead of apply_if. In that case, it would have given
a "lazy" result, as well. :)

Thanks for your comments.

Regards,

Terje


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