Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-09-28 12:07:49


Anakreon wrote:

> struct event_locator: public unary_function<bool, Event*> {
> 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;
}

and then use bind( has_transaction_with_id, _1, tid ) as the predicate. You
can also define hasTransactionWithId as a member of Event and then use
bind( &Event::hasTransactionWithId, _1, tid ).

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.


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