Using lambda expressions in stl algorithms

Hello, Could someone tell me why this code does not compile? Can it be modified in order to compile? struct CcyCplEventKey { CurrencyCouple CcyCpl; EventType Event; } typedef std::map<CurrencyEventKey, CurrencyEventPtr> mapType; mapType ccyOut; std::for_each(ccyOut.begin(), ccyOut.end(), (&*boost::lambda::_1)->*&CcyCplEventKey::Event); Cheers ___________________________________________________________ This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited. Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-8... for additional disclosures.

On Tue, Dec 14, 2010 at 2:49 PM, <przemyslaw.sliwa@uk.bnpparibas.com> wrote:
Hello,
Could someone tell me why this code does not compile? Can it be modified in order to compile?
struct CcyCplEventKey { CurrencyCouple CcyCpl; EventType Event; }
typedef std::map<CurrencyEventKey, CurrencyEventPtr> mapType;
mapType ccyOut;
std::for_each(ccyOut.begin(), ccyOut.end(), (&*boost::lambda::_1)->*&CcyCplEventKey::Event);
Cheers
Ummm - for a start, a std::map iterator references a std::pair containing the key and value for that map entry, so you need to get hold of the 'first' member of the std::pair to use the key. Without type definitions for EventType, CurrencyEventPtr and CurrencyCouple, it's difficult to go further than that... Stuart Dootson

AMDG On 12/14/2010 6:49 AM, przemyslaw.sliwa@uk.bnpparibas.com wrote:
Could someone tell me why this code does not compile? Can it be modified in order to compile?
struct CcyCplEventKey { CurrencyCouple CcyCpl; EventType Event; }
typedef std::map<CurrencyEventKey, CurrencyEventPtr> mapType;
mapType ccyOut;
std::for_each(ccyOut.begin(), ccyOut.end(), (&*boost::lambda::_1)->*&CcyCplEventKey::Event);
boost::lambda::_1 gets replaced with an object of type std::pair<const CurrencyEventKey, CurrencyEventPtr>. a) std::pair can't be dereferenced. b) Even if it could be, you can't call a member function of CcyCplEventKey with a std::pair. c) Accessing a data member has no side-effects. The for_each doesn't do anything, so I don't know what you're trying to accomplish. In Christ, Steven Watanabe
participants (3)
-
przemyslaw.sliwa@uk.bnpparibas.com
-
Steven Watanabe
-
Stuart Dootson