Boost logo

Boost Users :

From: Lucio Flores (dogboy_l_at_[hidden])
Date: 2006-03-01 19:46:10

--- 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;

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?


Manson: My philosophy is: Don't think. I don't believe in the mind that you think with and scheme with. I don't believe in words.

Reporter: If you don't believe in words, why do you use so many of them?

Manson: Words are symbols. All I'm doing is jumbling the symbols in your brain. Everything is symbolic. Symbols are just connections in your brain. Even your body is a symbol.

Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around

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