Re: Boost::mpl vector product
Larry Evans <cppljevans <at> suddenlink.net>
2012-02-01 11:49:59 GMT
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 <cppljevans <at> suddenlink.net> 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
Hi Larry,
> Hi Abel,
>
> I thought maybe you'd be interested in using your
> library to solve the problem mentioned in the
>
> Boost::mpl vector product
>
> problem posed in this thread:
>
> http://article.gmane.org/gmane.comp.lib.boost.user/72558
>
> I'd be curious to see if it can be done.
> I hope it can.
Yes, it can. List comprehension can be implemented using the do notation
(http://www.haskell.org/tutorial/monads.html#sect9.2). Since Metamonad
supports the do notation, you can solve the problem the following way:
using boost::mpl::pair;
using mpllibs::metamonad::list_tag;
using mpllibs::metamonad::do_;
using mpllibs::metamonad::set;
using mpllibs::metamonad::do_return;
struct l1;
struct l2;
typedef
do_<list_tag>::apply<
set<l1, v1>,
set<l2, v2>,
do_return<pair<l2, l1> >
>::type
result;
Note that the list monad uses mpl::transform internally which doesn't
work with range_c, thus v2 has to be a sequence that is a copy of
range_c<....>
(http://www.boost.org/doc/libs/1_48_0/libs/mpl/doc/refmanual/range-c.html).
Regards,
Abel
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users