|
Boost Users : |
From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-05-10 09:51:04
Ares Lagae ha escrito:
[...]
> I was wondering, however, if variable_list_member can be eliminated, and
> my_type passed as a template argument. E.g. suppose I write a metafunction
>
> template <typename T> struct my_type { typedef /* some type */ type; }
>
> to somehow declare
>
> typedef variable_list_seq<boost::mpl::vector<int, char, double>, my_type>
> vl_type;
>
> to obtain a variable list with "keys" int, char, double and variables of
> type my_type<int>::type, ....
Yep, this can be done adding an optional template parameter to
variable_list_seq,
as shown in the example attached. Note that variable_list_member is not
elminated, but merely supplemented with your my_type metafunction
so as to be able to customize member types.
> 2/ would it be possible to generated variables my_type<T1, T2> for all
> possible combinations of T1 and T2, where T1 and T2 are types in two
> typelists?
>
> Something like
>
> typedef product_variable_list_seq<boost::mpl::vector<...>,
> boost::mpl::vector<...>, my_type> vl_type;
>
> where my_type is a
>
> template <typename T1, typename T2> struct my_type { typedef /* some type */
> type; }
>
Again, starting from the simpler variable_list_seq one can write a new
product_variable_list_seq working on the cartesian product of two MPL
sequences:
template<typename T> struct pair_with:boost::mpl::pair<T,boost::mpl::_>{};
template<typename Sequence1,typename Sequence2>
struct sequence_product:
boost::mpl::fold<
Sequence1,
boost::mpl::vector0<>,
boost::mpl::joint_view<
boost::mpl::_1,
boost::mpl::transform<
Sequence2,
pair_with<boost::mpl::_2>
>
>
>
{};
The file attached also exercises a possible implementation. Things are
a little more complex now, I strongly suspect this kind of stuff can
be more easily done with fusion, but alas I haven't had time to learn
about that lib.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net