Boost logo

Boost Users :

Subject: Re: [Boost-users] boost lambda for processing std::vector
From: CR Koudella (ckoudell_at_[hidden])
Date: 2009-11-29 21:14:07


thanks, I have started to look at the doc, but I am not there yet.

imagine we have something like this, without too much thought and excuse
the basic style laid out here:

struct XMapVec
{
public:
XMapVec(const std::vector<double> & vY, const std::vector<unsigned> & vMap)
: _vY(vY), _vMap(vMap), _vBuffer(vMap)
{
}

std::vector<double> operator()(const std::vector<double> & vX) const
{
unsigned nCnt = 0
for (int nI = 0; nI < _vBuffer.size(); ++nI)
{
    if (_vMap[nI])
    {
        _vBuffer[nI] = vX[nCnt];
        ++nCnt;
    }
}

return _vBuffer;
}
private:

// assume _vY same size as _vMap
// the state
std::vector<double> _vY;
// binary Map: if element = 1, then update corresponding entry in _vBuffer
std::vector<unsigned> _vMap;
// set initial state at construction and mutate relevant elements on () call
mutable std::vector<double> _vBuffer;
};

this is not nicely written, but more importantly it is not nice to have this in
a dedicated functor. the question is, how to rewrite this in terms of a lambda
expression, which can then be used in a function composition operation?

thanks,
ChrisK

> Date: Sun, 29 Nov 2009 18:37:10 -0700
> From: overminddl1_at_[hidden]
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] boost lambda for processing std::vector
>
> On Sun, Nov 29, 2009 at 10:25 AM, CR Koudella <ckoudell_at_[hidden]> wrote:
> >
> > Thanks for your answer. I see, I am pretty out of time here. I will look
> > into phoenix.
> > Can you provide an indication as to how you would handle my example with
> > phoenix?
> > That would be of great help.
>
> First, the docs:
> http://boost-spirit.com/dl_docs/phoenix-2/libs/spirit/phoenix/doc/html/index.html
>
> Second, I am not sure what exactly you are wanting done, wanting to
> generate {3,1,3,1,3} from {3,3,3} or something? Do you have some
> pseudo-code?
>
>
> On Sun, Nov 29, 2009 at 10:25 AM, CR Koudella <ckoudell_at_[hidden]> wrote:
> > PS: If this message doesn't end up in the right thread, I apologize. I
> > haven't figured
> > out how to reply to the list... Do I have to not user list receive messages
> > in a digest,
> > but receive them one by one?
>
> You did it correct, and yes, receiving one-by-one is much easier. :)
> _______________________________________________
> 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