Re: [Boost-users] boost lambda for processing std::vector
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. 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?
On Sun, Nov 29, 2009 at 10:25 AM, CR Koudella
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...
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
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. :)
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@gmail.com To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost lambda for processing std::vector
On Sun, Nov 29, 2009 at 10:25 AM, CR Koudella
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...
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
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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, Nov 29, 2009 at 7:14 PM, CR Koudella
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.
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
On Mon, Nov 30, 2009 at 6:52 AM, CR Koudella
Hi OvermindDL1,
thanks again. You are bringing up yet another library here. I need to do some study. Will write again.
Actually, ignore my Fusion pip, I initially wrote it more 'generically' using Fusion, but figured to just simplify it with the example I did give and never took out that Fusion pip I added. ^.^
I'm trying to use the mac ports version of boost 1.41 on mac os 10.6, XCode 3.2. I'm running in to problems due to (I think) the fact that the mac os version of g++ 4.2.1 includes it own definition of the tr1 tuple. This results duplicate definitions when the boost/tr1/tuple.hpp header is included in a file (and some boost headers include it internally). What is the right way to work around this? I see various preprocessor symbols I can define, but an not sure what the cleanest way is. Thanks. --Daniel
I'm trying to use the mac ports version of boost 1.41 on mac os 10.6, XCode 3.2. I'm running in to problems due to (I think) the fact that the mac os version of g++ 4.2.1 includes it own definition of the tr1 tuple. This results duplicate definitions when the boost/tr1/tuple.hpp header is included in a file (and some boost headers include it internally). What is the right way to work around this? I see various preprocessor symbols I can define, but an not sure what the cleanest way is. Thanks.
Try BOOST_HAS_GCC_TR1, HTH, John.
participants (4)
-
CR Koudella
-
Daniel Russel
-
John Maddock
-
OvermindDL1