hello,
relating to my earlier post, the code for the 2-seq and 3-seq cross product is:
#include
#include
#include
#include
#include
#include
namespace mpl = boost::mpl;
using namespace mpl::placeholders;
template <typename T>
struct pair_with : mpl::pair {};
template <typename pair>
struct triple_with : mpl::vector3 {};
// public metafunction
template
struct sequence2_cross_product :
mpl::fold<
Sequence1,
mpl::vector0<>,
mpl::copy<
mpl::transform<
Sequence2,
pair_with<_2>
>,
mpl::back_inserter<_1>
>
{};
template< typename SequencePair, typename Sequence>
struct seq_seqpair_product :
mpl::fold<
SequencePair,
mpl::vector0<>,
mpl::copy<
mpl::transform<
Sequence,
triple_with<_2>
>,
mpl::back_inserter<_1>
>
{};
// public metafunction
template
struct sequence3_cross_product : seq_seqpair_product< typename sequence2_cross_product::type, Sequence3>
{};
usage is like:
S1: any MPL sequence with T11, T12, T13...T1k types
S2: any MPL sequence with T21, T22, T23...T2m types
S3: any MPL sequence with T31, T32, T33...T3n types
typedef sequence2_cross_product::type binary_product;
/* this will be a mpl::vector< pair,
pair,
...
pair,
pair,
pair,
...
pair > */
// and
typedef sequence3_cross_product::type ternary_product;
/* this will be same mpl::vector, but with
vector3 ..... instead */
1) I'm trying to make these metafunctions general enough,
perhaps in the future i might use them for something
i'm not thinking about now....
i would like to let the caller (me), choose what tuple/template
to embed the resulting Tij, Tkl in...
. for the sequence2_cross_product metafunction, mpl::pair,
or mpl::vector2 or any class template that takes 2 type template
arguments, or i could restrict the user to something that
interacts well with mpl, is it "lambda expressions" or "metafct"
or "metafct class"?
. for the sequence3_cross_product metafunction, mpl::vector3 or
any class template that takes 3 type template args... same question
2) I have a class template RT (not metafct or metafct class),
that takes 3 template args, for each of these args, i have a
list of possible types (in an mpl sequence),
then i have a class R.
I would like to define
2.1. typedef boost::variant< R, RT, RT.... > R;
2.2. do an explicit template instantiation of all the RT<..,..,..>
Should i use Boost.PP for this, e.g.:
#include
#include
#define Type1 (T11)(T12)(T13)...(T1k)
#define Type2 (T21)(T22)(T23)...(T2k)
#define Type3 (T31)(T32)(T33)...(T3k)
#define M(r, product) template class RT;
BOOST_PP_SEQ_FOR_EACH_PRODUCT(M, (Type1)(Type2)(Type3))
#undef Type1
#undef Type2
#undef Type3
#undef M
and what about variant<...>, how would i write it with PP?
comment, thoughsts are appreciated,
thanks,
regards,