Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] at_key + for_each
From: Denis Taniguchi (taniguchi_at_[hidden])
Date: 2010-05-04 14:58:35


On Tue, 2010-05-04 at 19:32 +0200, Kim Kuen Tang wrote:
> Christopher Schmidt schrieb:
> > Denis Taniguchi schrieb:
> >> Hi,
> >>
> >> I was trying to implement something equivalent to the following piece of
> >> code:
> >>
> >> template<class Field1, class Field2, ... , class FieldN, class Range,
> >> class Function>
> >> Function for_each(Range&r, Function f)
> >> {
> >> using namespace boost;
> >> using namespace boost::fusion;
> >>
> >> BOOST_FOREACH(typename range_value<Range>::type&v, r)
> >> {
> >> at_key<Field1>(v) = f(at_key<Field2>(v), at_key<Field3>(v), ... ,
> >> at_key<FieldN>(v));
> >> }
> >> return f;
> >> }
> >>
> >> Is there a simple way to do this using fusion's current functionalities?
> >
> > If you pass Field2...FieldN wrapped in a mpl sequence, its quiete
> > simple. See the attached code for an example implementation.
> >

Well, I didn't find it simple like you, but it worked like a charm.
Thanks a lot!

> Hi Christopher,
>
> yes, you are right. The function fusion::invoke is able to do it.
>
> However, IMHO using the preprocessor for this paricular situation will
> suit it more.
> Just my opinion.
>

Could you explain it a little bit more Kim? A working piece of code would be great too. =)

> -Kim
>
> > -Christopher
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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