
Hi OvermindDL1, thanks again. You are bringing up yet another library here. I need to do some study. Will write again. Thanks, ChrisK
Date: Sun, 29 Nov 2009 19:47:49 -0700 From: overminddl1@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost lambda for processing std::vector
On Sun, Nov 29, 2009 at 7:14 PM, CR Koudella
wrote: 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?
Looks like an accumulator... Well a completely lazy version of that could be (using both phoenix and fusion):
std::vector<double> vY; std::vector<unsigned> vMap; std::vector<double> vBuffer;
// Assuming vY is the same size as vMap and vBuffer auto XMapVec = let(_a=begin(vY),_b=begin(vMap),_c=begin(vBuffer),_d=end(vY),_e=(unsigned)0) [ for_(nothing,_a!=_d,(++_a,++_b,++_c)) [ if_(*_b) [ (*_c) = _1(_e), ++_e ] ] ];
This is not nicely written either, but demonstrates how it can be used anyway.
This is still completely untested, I am still at work. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users