Boost logo

Boost :

From: Michael Goldshteyn (mgoldshteyn_at_[hidden])
Date: 2005-03-08 17:26:46


// Definitions

class Element
  const std::string &GetTag() const;

typedef std::vector<Element> ElementContainer;

// Now here is what is required

ElementContainer elements;
ElementContainer matchingElements;
std::string matchingTag("abc");


What is pred? Assuming that iElements represents the iterator inside 
copy_if, pred should be something like: iElements->GetTag()==matchingTag
I could go about this by creating a new function object class/struct, which 
takes matchingTag as its sole constructor argument and does the comparison 
inside operator(). But, I want to use in place composition using binders, 
etc... to create the pred, so as not to have to create a function object 
class/struct. The question is, "What piece of code should pred be?"
// Almost does the right thing, but it's only *iElements==matchingTag, I 
need iElements->GetTag()==matchingTag
This seems like a very common operation. How can I compose the predicate, in 
place to do this? If there are multiple solutions, I would like to hear them 
as well!

Boost list run by bdawes at, gregod at, cpdaniel at, john at