Peter Dimov wrote:
Anakreon wrote:
struct event_locator: public unary_function
{ int tId; event_locator(const int tid) : tId(tid) {} const bool operator() (Event* e) { return e->hasTransaction() && e->getTransaction().getId() == tId; } }; The best (IMO) approach would be to define
bool has_transaction_with_id( Event /*const?*/ * e, int id ) { return e->hasTransaction() && e->getTransaction().getId() == id; }
I intended to use lambda in order to avoid declaration of functions or structs for STL algorithms. If I need to declare the function above then I find no reason to use lambda at all.
You can use
bind( &Event::hasTransaction, _1 ) && bind( &Transaction::getId, bind( &Event::getTransaction, _1 ) ) == tid
but I'm not sure that you'd want to. It looks to complex.
Thanks Peter for the response.