Boost::mpl vector product

Hi
If I have two mpl vectors: v1 and v2
typedef boost::mpl::vector
Best regards Allan W. Nielsen

On 01/22/12 08:38, Allan Nielsen wrote:
Hi
If I have two mpl vectors: v1 and v2
typedef boost::mpl::vector
v1; typedef boost::mpl::range_c v2; Does boost then provide any tools for constructing the type:
boost::mpl::vector< boost::mpl::pair< int_<0>, char >, boost::mpl::pair< int_<1>, char >, boost::mpl::pair< int_<2>, char >, boost::mpl::pair< int_<3>, char >,
boost::mpl::pair< int_<0>, short >, boost::mpl::pair< int_<1>, short >, boost::mpl::pair< int_<2>, short >, boost::mpl::pair< int_<3>, short >,
boost::mpl::pair< int_<0>, int >, boost::mpl::pair< int_<1>, int >, boost::mpl::pair< int_<2>, int >, boost::mpl::pair< int_<3>, int >
Best regards Allan W. Nielsen
One name for this is operation is 'cross product'. Another is 'outer product': http://aplwiki.com/LearnApl/AplOperators#Outer_and_inner_products That problem was discussed in this thread: http://thread.gmane.org/gmane.comp.lib.boost.devel/171761 It was also posed as a problem 7-8 here: http://www.boostpro.com/mplbook/ One answer was posted here: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?CPPTM_Answers... HTH. -Larry

On 01/22/12 08:38, Allan Nielsen wrote:
Hi
If I have two mpl vectors: v1 and v2
typedef boost::mpl::vector
v1; typedef boost::mpl::range_c v2; Does boost then provide any tools for constructing the type:
boost::mpl::vector< boost::mpl::pair< int_<0>, char >, boost::mpl::pair< int_<1>, char >, boost::mpl::pair< int_<2>, char >, boost::mpl::pair< int_<3>, char >,
boost::mpl::pair< int_<0>, short >, boost::mpl::pair< int_<1>, short >, boost::mpl::pair< int_<2>, short >, boost::mpl::pair< int_<3>, short >,
boost::mpl::pair< int_<0>, int >, boost::mpl::pair< int_<1>, int >, boost::mpl::pair< int_<2>, int >, boost::mpl::pair< int_<3>, int >
Best regards Allan W. Nielsen The attached code uses variadic templates and code from:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/ and does what you want except, instead of mpl::pair, it produces an mpl::vector whose size is the number of mpl sequences on input. HTH. -Larry

On 01/22/12 12:03, Larry Evans wrote: [snip]
The attached code uses variadic templates and code from:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/
and does what you want except, instead of mpl::pair, it produces an mpl::vector whose size is the number of mpl sequences on input.
OOPS, forgot outer_product_pack, which is attached.

Cool thanks a lot
Best regards
Allan W. Nielsen
On Sun, Jan 22, 2012 at 7:41 PM, Larry Evans
On 01/22/12 12:03, Larry Evans wrote: [snip]
The attached code uses variadic templates and code from:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/
and does what you want except, instead of mpl::pair, it produces an mpl::vector whose size is the number of mpl sequences on input.
OOPS, forgot outer_product_pack, which is attached.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 01/23/12 02:03, Allan Nielsen wrote:
Cool thanks a lot
Best regards Allan W. Nielsen
On Sun, Jan 22, 2012 at 7:41 PM, Larry Evans
wrote: On 01/22/12 12:03, Larry Evans wrote: [snip]
The attached code uses variadic templates and code from:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/
and does what you want except, instead of mpl::pair, it produces an mpl::vector whose size is the number of mpl sequences on input.
OOPS, forgot outer_product_pack, which is attached.
You might also have a look at Abel Sinkovics metaprogramming library:
http://abel.web.elte.hu/mpllibs/metamonad/index.html I, as yet, have no idea of how to do what you want with Abel's library; however, I'd guess it could be done. In particular, I know list comprehensions: http://www.haskell.org/haskellwiki/List_comprehension ( which are, AFAICT, flattened outer products) can be done with monads which Abel's library supplies. Maybe you could ask Abel how to do this with his library. I'd be interested in seeing that. HTH. -Larry

On 01/30/12 09:32, Larry Evans wrote:
On 01/23/12 02:03, Allan Nielsen wrote:
Cool thanks a lot
Best regards Allan W. Nielsen
On Sun, Jan 22, 2012 at 7:41 PM, Larry Evans
wrote: On 01/22/12 12:03, Larry Evans wrote: [snip]
The attached code uses variadic templates and code from:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/
and does what you want except, instead of mpl::pair, it produces an mpl::vector whose size is the number of mpl sequences on input.
OOPS, forgot outer_product_pack, which is attached.
You might also have a look at Abel Sinkovics metaprogramming library:
http://abel.web.elte.hu/mpllibs/metamonad/index.html
I, as yet, have no idea of how to do what you want with Abel's library; however, I'd guess it could be done. In particular, I know list comprehensions:
http://www.haskell.org/haskellwiki/List_comprehension
( which are, AFAICT, flattened outer products) can be done with monads which Abel's library supplies.
Maybe you could ask Abel how to do this with his library. I'd be interested in seeing that.
HTH.
-Larry In a private email to me, Abel said his metaprogramming library could do this. I've attached a copy of his email. I don't know if you can use it, but I just thought it was interesting and may give some other ideas of how to solve your problem.
-regards, Larry
participants (2)
-
Allan Nielsen
-
Larry Evans