|
Boost Users : |
From: João Abecasis (jpabecasis_at_[hidden])
Date: 2006-03-01 09:27:59
Lucio Flores wrote:
> So as an exercise, I'm trying to use a lambda expression that applies the first
> argument twice on it's second argument.
>
>
> typedef mpl::apply<_1, mpl::apply<_1, _2>::type>::type twice_type;
>
> Then I instance this lambda function on boost::add_pointer and int
>
>
> typedef mpl::apply<twice_type, boost::add_pointer<_1>, int>::type result_type;
>
> But using boost::is_same, I've found that result_type==int, not int** as
> expected. Can someone see why?
If you look closely, as it is defined, twice_type is actually the same
as mpl::_2. Once you "invoke" the ::type member typedef you're
evaluating the metafunction and no longer have a lambda.
Here's a simple function I find useful in debugging template meta-code:
template <class type>
inline void print()
{
class _ { _() {} };
_ printer;
}
use it thus:
int main()
{
typedef mpl::apply<mpl::_1, mpl::_2>::type result;
print<result>();
}
You'll get a nice error message with the resulting type in it. This
should help you better understand what's going on.
You'll should look into protect and lambda to defer evaluation of the
metafunctions.
HTH,
João
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net