Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-01 11:52:02

"Eyal Farago" <eyal.farago_at_[hidden]> writes:

> hi, I'm trying to use mpl lambda on vc.6.5, it seems that for some
> reason when applying lambda on the expression the compiler tries to
> instantiate the wrong specialisation(the one with the
> boost::mpl::arg<1> as a template parameter.
> this is the test program:
> #include <boost/mpl/lambda.hpp>
> #include <boost/tuple/tuple.hpp>
> template< class T_ >
> struct head_type
> {
> typedef typename T_::head_type type;
> BOOST_MPL_AUX_LAMBDA_SUPPORT( 1, head_type, ( T_ ) );
> };
> void main()
> {
> typedef boost::tuples::tuple< int > int_tuple_t;
> typedef head_type< int_tuple_t >::type head_of_int_tuple_t;
> typedef head_type< boost::mpl::_1 > exp_t;
> typedef boost::mpl::lambda< exp_t >::type exp_lambda_t; //this line causes the compilation error
> typedef boost::mpl::apply1< exp_lambda_t, int_tuple_t >::type int_tuple_head_type;
> }

You've just discovered that there are some limitations to what we can
do even with workarounds. The usual cure is to supply your own
specialization of head_type<_1>

  template <>
  struct head_type<_1>
      template <class T>
      struct apply : head_type<T> {};

Yes, Aleksey and I have discussed generating these specializations
from BOOST_MPL_AUX_LAMBDA_SUPPORT, but when you consider all the
combinations that you might want to generate in general, you get a
combinatorial explosion for multi-argument metafunctions and it still
doesn't handle all cases :(

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at