|
Boost Users : |
Subject: Re: [Boost-users] [fusion] const and transform algorithm
From: Joel de Guzman (joel_at_[hidden])
Date: 2009-01-06 17:26:52
vicente.botet wrote:
> Hi,
>
> What is the reason fusion::transform taskes a const Sequence?
> template<
> typename Sequence,
> typename F
> >
> typename result_of::transform<Sequence const, F>::type transform(
> Sequence const& seq, F f);
>
> Does this means that the transform do not change the sequence itself o also its elements?
Yes. Fusion transform returns a lazy (transform) view. This view
is non-mutating. It is not like STL's transform which mutates
the target container in place. Fusion's is purely functional and
lazily evaluated.
> Why the following do not compiles
> struct get {
> template<typename Sig> struct result;
> template<typename T> struct result<get(T)> {
> typedef typename boost::remove_reference<T>::type ACT;
> typedef typename ACT::result_type type;
> };
> template<typename ACT>
> typename ACT::result_type operator()(ACT& act) const
> { return act.get(); }
> };
> boost::tuple<shared_future<int>,shared_future<char> > t;
> boost::fusion::result_of::transform<
> boost::tuple<shared_future<int>,shared_future<char> > , get>::type res=
> boost::fusion::transform(t, get());
>
> transform call to get()(const shared_future<int>&act). How can I make a transformation changing also the sequence itself?
>
> The result of transform is a transform_view, so the function get is not really called. How can I assign this to a
> boost::tuple<int, char> = ??(boost::fusion::transform(t, get()));
> boost::as_vector? Is there a as_tuple function? Should this force the evaluation of the get function?
As I said, Fusion transform is purely functional. The result of a transform
is a view. The function will only be called when you iterate over the
view. The transformation does not change/mutate the sequence itself.
If that's what you want, you can assign the view back to the original
container. For example:
vector<int, char> v;
v = transform(v, f);
Regards,
-- Joel de Guzman http://www.boostpro.com http://spirit.sf.net
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