
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; } and this is the compiler's output: --------------------Configuration: boost_tests - Win32 Debug-------------------- Compiling... main.cpp C:\c++\boost_tests\main.cpp(7) : error C2039: 'head_type' : is not a member of 'arg<1>' c:\c++\boost_1_30_0\boost\mpl\aux_\preprocessed\msvc60\arg.hpp(28) : see declaration of 'arg<1>' c:\c++\boost_1_30_0\boost\type_traits\is_convertible.hpp(64) : see reference to class template instantiation 'head_type<struct boost::mpl::arg<1> >' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_convertible.hpp(80) : see reference to class template instantiation 'boost::detail::does_conversion_exist<struct head_type<struct boost::mpl::arg<1> > &>::result_<struct boost::detail::int_convertible
' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_convertible.hpp(184) : see reference to class template instantiation 'boost::detail::is_convertible_basic_impl<struct head_type<struct boost::mpl::arg<1> > &,struct boost::detail::int_convertible>' be ing compiled c:\c++\boost_1_30_0\boost\type_traits\is_convertible.hpp(239) : see reference to class template instantiation 'boost::detail::is_convertible_impl<struct head_type<struct boost::mpl::arg<1> > &,struct boost::detail::int_convertible>' being co mpiled c:\c++\boost_1_30_0\boost\type_traits\is_enum.hpp(54) : see reference to class template instantiation 'boost::is_convertible<struct head_type<struct boost::mpl::arg<1> > &,struct boost::detail::int_convertible>' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_enum.hpp(91) : see reference to class template instantiation 'boost::detail::is_enum_helper<0>::type<struct head_type<struct boost::mpl::arg<1> > &>' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_enum.hpp(108) : see reference to class template instantiation 'boost::detail::is_enum_impl<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_scalar.hpp(30) : see reference to class template instantiation 'boost::is_enum<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_scalar.hpp(50) : see reference to class template instantiation 'boost::detail::is_scalar_impl<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_class.hpp(78) : see reference to class template instantiation 'boost::is_scalar<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\type_traits\is_class.hpp(93) : see reference to class template instantiation 'boost::detail::is_class_impl<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\mpl\aux_\has_rebind.hpp(32) : see reference to class template instantiation 'boost::is_class<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\mpl\aux_\preprocessed\msvc60\template_arity.hpp(27) : see reference to class template instantiation 'boost::mpl::aux::has_rebind<struct head_type<struct boost::mpl::arg<1> > >' being compiled c:\c++\boost_1_30_0\boost\mpl\aux_\preprocessed\msvc60\lambda_no_ctps.hpp(150) : see reference to class template instantiation 'boost::mpl::aux::template_arity<struct head_type<struct boost::mpl::arg<1> > >' being compiled C:\c++\boost_tests\main.cpp(17) : see reference to class template instantiation 'boost::mpl::lambda<struct head_type<struct boost::mpl::arg<1> >,1>' being compiled Error executing cl.exe.
boost_tests.exe - 1 error(s), 0 warning(s) eyal.

"Eyal Farago" <eyal.farago@actimize.com> 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 www.boost-consulting.com
participants (2)
-
David Abrahams
-
Eyal Farago