Boost logo

Boost :

Subject: Re: [boost] Proposed addition to the iterator library for iterating over all tuples.
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-06-16 15:38:35


On 08/01/05 03:41, Alex Mendes da Costa wrote:
> Quick update: I currently have a partial (but working) implementation
> of the cross_iterator. I hope to have a preliminary submission ready
> some time this week.
>
> Alex
>
> On 7/26/05, David Abrahams <dave_at_[hidden]> wrote:
>> Alex Mendes da Costa <alexmdac_at_[hidden]> writes:
>>
>>> The iterator that I am proposing would provide the sequence (1,10),
>>> (2,10), (1,20), (2,20).
>> Oh, you want a cross-product iterator. Interesting idea.

A haskell list comprehension is what you need, AFAICT.

FC++ can do this, if I'm correctly interpreting pages 16,19-20 of:

   http://www-static.cc.gatech.edu/~yannis/fc++/fcpp-lambda.pdf

For example, p. 19 uses (in haskell syntax):

    [x+y|x <- [1,2,3], y <- [2,3], x<y]

to produce:

   [3,4,5]

(as shown on p. 16), and the corresponding FC++:

   compM<ListM>
     [ X %plus% Y
     | X <= list_with(1,2,3)
     , Y <= list_with(2,3)
     , guard[X %less% Y]
     ]

is shown just below the haskell code on p. 19.

In your case, I guess the X %plus% Y would maybe be replaced with
some sort of mpl sequence, e.g. mpl::list<X,Y>, and for more than
2 domans, I'd guess you'd have to have:

   mpl::list<D1,D2,...,Dn>

Also, maybe FC++ could be adapted to make this easier. Hmm..
maybe mpl::fold could be combined with compM to do this for
any number of domains.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk