Good afternoon, I have this question: I define my data type

typedef struct { string name; string avtor; string place; /* и т.д. */ } librery; 

Create a list

 list< librery> bibl; 

I fill it with values, I need to find an element (or all elements) in the list, suppose by the name field, and delete them. Tell me, please, how to do it.

    1 answer 1

    It is possible so:

     struct NameEqualTo { NameEqualTo(const std::string& name) : name_(name) {} bool operator()(const librery& l) const {return == name_;} std::string name_; }; bibl.remove_if(NameEqualTo("John")); 

    If you use boost, you can write shorter:

     bibl.remove_if(boost::bind(&librery::name, _1) == "John"); 

    You can just remove the pens:

     for (std::list<librer>::iterator it = bibl.begin(); it != bibl.end();) { if (it->name == "John") { it = bibl.erase(it); } else { ++it; } }