[mpl::transform] How to make metafunction from transform?
Hello All! I want to parametrize mpl::transform to form a new metafunction. But I have confused with mpl syntax and notations. Imagine, I have following vector typedef boost::mpl::vector<Type1, Type2, Type3, Type4> types; and following transformation: typedef boost::mpl::transform< types , boost::is_convertible<Type3, boost::mpl::_1>
::type result;
The result of the tansformation is a bool vector that indicates whether Type3 is convertible to any of type from types vector. Now I want to form metafunction that will construct such array not from Type3, but from its argument. Of course, I may use straightforward method: struct WhoConverted { template <typename ConversionType> struct apply { typedef typename boost::mpl::transform< types , boost::is_convertible<ConversionType, boost::mpl::_1> >::type type; }; }; But it seems more like workaround rather than solution. Can it be done in more convenient and short manner by means of all mpl machinery like mpl::lambda, mpl::bind, placeholders, etc... ? -- Vyacheslav E. Andrejev System Architect, Excelsior, LLC
Vyacheslav E. Andrejev writes:
I want to parametrize mpl::transform to form a new metafunction. But I have confused with mpl syntax and notations. Imagine, I have following vector
typedef boost::mpl::vector<Type1, Type2, Type3, Type4> types;
and following transformation:
typedef boost::mpl::transform< types , boost::is_convertible<Type3, boost::mpl::_1>
::type result;
The result of the tansformation is a bool vector that indicates whether Type3 is convertible to any of type from types vector. Now I want to form metafunction that will construct such array not from Type3, but from its argument. Of course, I may use straightforward method:
struct WhoConverted { template <typename ConversionType> struct apply { typedef typename boost::mpl::transform< types , boost::is_convertible<ConversionType, boost::mpl::_1> >::type type; }; };
Or template< typename T > struct WhoConverted : boost::mpl::transform< types , boost::is_convertible<T, boost::mpl::_1> > { };
But it seems more like workaround rather than solution.
It's inconvenient to have to write (and name) an auxiliary template that has no other uses, yes.
Can it be done in more convenient and short manner by means of all mpl machinery like mpl::lambda, mpl::bind, placeholders, etc... ?
At the moment, the above is the best you can have. I'm considering implementing lambda scoping along the lines of http://article.gmane.org/gmane.comp.lib.boost.devel/116000 for the next release. HTH and sorry for the late reply, -- Aleksey Gurtovoy MetaCommunications Engineering
Hello Aleksey, Thank you for reply. Your suggestion looks much more attractive than code I have already implemented. But, yes, unfortunatly, there is still named auxiliary template. Anyway thanks, because by means of MPL I could write curious engine that takes mpl vector of types and builds runtime graph of available conversions between these types. The engine allows to find a chain of conversions that we have to make in order to convert any type to any if this conversion is somehow possible. Regards. -- Vyacheslav E. Andrejev System Architect, Excelsior, LLC AG> Or AG> AG> template< typename T > struct WhoConverted AG> : boost::mpl::transform< AG> types AG> , boost::is_convertible<T, boost::mpl::_1> AG> { AG> }; AG> AG> It's inconvenient to have to write (and name) an auxiliary template AG> that has no other uses, yes. AG> AG> At the moment, the above is the best you can have. I'm considering AG> implementing lambda scoping along the lines of AG> http://article.gmane.org/gmane.comp.lib.boost.devel/116000 for the AG> next release. AG> AG> HTH and sorry for the late reply, AG>
participants (2)
-
Aleksey Gurtovoy
-
Vyacheslav E. Andrejev