Boost logo

Boost Users :

Subject: Re: [Boost-users] fusion: work of 4 sequences at the same time
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-18 13:05:08


> -----Original Message-----
> From: Hicham Mouline [mailto:hicham_at_[hidden]]
> Sent: 18 February 2010 17:38
> To: 'boost-users_at_[hidden]'
> Subject: fusion: work of 4 sequences at the same time
>
> Hi,
>
> I am trying to apply fusion::for_each on a sequence, but inside the unary
> functor applied to each element, I need to know the index of the element
in
> question, because I need to extract elements with the same index from
other
> sequences.
>
> fusion::vector<...> fseq1;
> fusion::vector<...> fseq2;
> fusion::vector<...> fseq3;
> fusion::vector<...> fseq4;
>
> fusion::for_each( fseq1, functor<...>(fseq2, fseq3, fseq4) );
>
> template <typename Seq2, typename Seq3, typename Seq4)
> struct functor {
> /// ctor
>
> template <typename T>
> void operator()( const T& t) const
> {
> /// find out index of t in fseq1,
> /// use elements from fseq2,3,4 at the same index
> }
> };
>
> I could use boost::fusion::find to get an iterator and then get its index,
but
> this doesn not look clean,
>
> Any ideas,
>
> Rds,
>
Ah!

fusion::zip is my friend.

fusion::for_each( fusion::zip(fseq1, fseq2, fseq3, fseq4), functor() );

Could u confirm though that I will be able to modify fseq1, even through the
zipping?

Rds,


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