Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterators for the cartesian product
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-06-13 08:19:54


On 06/13/11 06:37, kelvSYC wrote:
> So that the wheel doesn't have to be reinvented if it's already out
> there, is there something in boost that will take a bunch of
> sequences (lists, say) and return a sequence containing the
> cartesian product all of them, either as a tuple or after applying a
> function to them?

> For example, is there something in boost that will, given a bunch of
> lists of integers, return a list of integers formed by multiplying
> together one member from each list?

To be more concrete, say you have:

  std::vector<int> x({1,2,3});
  std::vector<int> y({4,5});

and what you want is something like:

  std::vector<std::vector<int> > z
  ( { { 4, 5}
    , { 8, 10}
    , { 12, 15}
    }
  };

Is that about right? If so, then this is also called outer_product
(at least in apl that's what it's called):

   http://en.wikipedia.org/wiki/Outer_product

I'm guessing this is also closely related to list comprehension in
haskell:

  http://www.haskell.org/haskellwiki/List_comprehension

There is some code in boost's vault which was announced on the boost
developer's mailing list in December 2010.

  http://thread.gmane.org/gmane.comp.lib.boost.devel/211905/focus=211919

HTH.

-regards,
Larry


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