Unable to work out a Composite predicate.
Hello everyone, I am not able to figure out the correct syntax for something I am trying to do. The following works as expected. It filters all the 'new' events into a new vector. remove_copy_if ( myEvents.begin(), myEvents.end(), back_inserter(newEvents), !(boost::bind(&Event::GetEventType, _1) == EventType_New)); I cant figure out how to get a complex conditional working as the predicate. e.g. remove_copy_if ( myEvents.begin(), myEvents.end(), back_inserter(newEvents), (boost::bind(&Event::GetEventType, _1) == NotesEventType_New) && (boost::bind(&Event::GetEventID, _1) == 1000 ) ); I have tried various ways of putting parens around this expression. I just couldn't get it to compile. Is that even possible ? Please Advise. I am using Visual C++ 2005 SP1 on Windows XP SP2. Appreciate your time. thanks pj
PJ Durai
Hello everyone,
remove_copy_if ( myEvents.begin(), myEvents.end(), back_inserter(newEvents), (boost::bind(&Event::GetEventType, _1) == NotesEventType_New) && (boost::bind(&Event::GetEventID, _1) == 1000 ) );
I have tried various ways of putting parens around this expression. I just couldn't get it to compile. Is that even possible ? Please Advise.
maybe this works: const std::vector<Event> v; std::vector<Event> vOut; std::remove_copy_if(v.begin(), v.end(), back_inserter(vOut), boost::bind(std::logical_and<bool>(), (boost::bind(&Event::GetEventType, _1) == 0), (boost::bind(&Event::GetEventID, _1) == 1)));
At 07:07 AM 8/25/2007, gast128 wrote:
remove_copy_if ( myEvents.begin(), myEvents.end(), back_inserter(newEvents), (boost::bind(&Event::GetEventType, _1) == NotesEventType_New) && (boost::bind(&Event::GetEventID, _1) == 1000 ) );
maybe this works:
const std::vector<Event> v; std::vector<Event> vOut;
std::remove_copy_if(v.begin(), v.end(), back_inserter(vOut), boost::bind(std::logical_and<bool>(), (boost::bind(&Event::GetEventType, _1) == 0), (boost::bind(&Event::GetEventID, _1) == 1)));
Alternatively, using boost::lambda::bind rather than boost::bind might permit you to use your original && syntax. (I haven't tried, though.)
On 8/25/07, gast128
PJ Durai
writes: Hello everyone,
remove_copy_if ( myEvents.begin(), myEvents.end(), back_inserter(newEvents), (boost::bind(&Event::GetEventType, _1) == NotesEventType_New) && (boost::bind(&Event::GetEventID, _1) == 1000 ) );
I have tried various ways of putting parens around this expression. I just couldn't get it to compile. Is that even possible ? Please Advise.
maybe this works:
const std::vector<Event> v; std::vector<Event> vOut;
std::remove_copy_if(v.begin(), v.end(), back_inserter(vOut), boost::bind(std::logical_and<bool>(), (boost::bind(&Event::GetEventType, _1) == 0), (boost::bind(&Event::GetEventID, _1) == 1)));
That worked. Thanks! pj
participants (3)
-
gast128
-
Nat Goodspeed
-
PJ Durai