Boost logo

Boost Users :

From: João Abecasis (jpabecasis_at_[hidden])
Date: 2006-03-02 10:10:53

Lucio Flores wrote:
> --- João Abecasis <jpabecasis_at_[hidden]> wrote:
>> 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.
> Ah.... ok so to create a proper lambda metafunction, I'm typing:
> typedef mpl::apply<_1, mpl::apply<_1, _2> > twice_type;
> Then to invoke it, I tried doing
> typedef mpl::apply<twice_type::type, boost::add_pointer<_1>, int> result_type;

twice_type::type is an invocation of twice_type, so you're almost back
to square one. Using the print utility


, I get (edited for readability)

     error: ‘print()::_::_()
         [with type = mpl::apply<mpl::_1, mpl::_2>]’ is private
     error: within this context

> But boost::is_same<result_type, int**>::value is also false.
>> Here's a simple function I find useful in debugging template meta-code:
>> template <class type>
>> inline void print()
>> {
>> class _ { _() {} };
>> _ printer;
>> }
> I see, I'm supposed to read the type description from the compiler error.
> Slick!! But the compiler doesn't describe the full description:
> prog_3_6.cpp: In function `void print() [with type = result_type]':
> prog_3_6.cpp:32: instantiated from here
> prog_3_6.cpp:9: error: `print()::_::_() [with type = result_type]' is private
> gcc version 3.3.5 20050117 (prerelease) (SUSE Linux)
> Maybe a compiler flag is needed to make it describe the full type?

Typedefs can interfere with the print utility. That said, you got what
you asked for. I'm assuming you wrote


Perhaps what you're really after is,


, since you already know what result_type is from the typedef above.

Best regards,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at