Boost logo

Boost Users :

Subject: Re: [Boost-users] boost lambda for processing std::vector
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-11-28 21:40:30


On Sat, Nov 28, 2009 at 6:40 AM, CR Koudella <ckoudell_at_[hidden]> wrote:
>
> Hi,
>
> I am trying to understand if boost.lambda is well suited for the quick
> processing of an std::vector<double>.
> I must apologize for my sketchy understanding of the library and this is the
> reason why I turn to you for
> your help.
>
> Imagine that we are given an std::vector<double>, say, x', of some size and
> that we need to extend x'
> somehow to x in order to use it as an argument for some function f.
>
> So, say x' = (3,3,3) and x can be obtained by some map as x = (3,1,3,1,3).
>
> Ideally, this problem would fit into function composition using bind or
> lambda::bind. Define g(x) = f[x(x')].
> The composition operation is standard. What is not for me is how to write
> the function x(x') using
> boost.lambda.
>
> It is always possible to write a quick C++ functor that will encode in its
> state the map defining how to
> generate x from x'. This would typically proceed by constructing a return
> std::vector<double> to be
> populated according to the map. But, can this be done easily with
> boost.lambda also? I am not sure. I
> seem to be finding it difficult to formulate expressions that return types
> such as std::vectors, while
> operating on the vector elements. I can see that the library is well suited
> to write small functors on the fly
> that will operate on container items (as is documented), but when it comes
> to full containers, I am kind of
> stuck. Any attempt seems to be leading to complicated script and dead ends,
> which makes me think that
> I am better off relegating the case to a small C++ functor written elsewhere
> in the file.
>
> Not sure if you see where I am coming from, but in a functional programming
> language or a higher level scripting
> language such as python, this kind of operation is quite easy to do on the
> fly. What I am trying to figure out
> is how much of the 'in-place definition of code in c++' should reasonably be
> handled with boost.lambda. Again,
> I can clearly see the power of boost.lambda when applied to std::for_each or
> std::transform, etc..., but I am
> not sure how to leverage it beyond that and I haven't seen many examples out
> there trying to do that either.
>
> Insights and help greatly appreciated,

Use Boost.Phoenix, it does everything Boost.Lambda does and a lot
more, as well as having vector handling functionality already
built-in.


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