c++ - How to remove vector of struct that contains vector of int -
i want delete val[i]
follows:
struct sstruct{ int v1; double v2; }; struct sstruct2{ std::vector<int> id; double a; std::vector<sstruct > b; }; std::vector <sstruct2> val;
i tried code got error, using std::remove_if
bool testfun(sstruct2 id1) { bool result= true; if ((id1.a< somevalue) { // fails result= false; } return result; } void delfun() { (int i= 0; i< val.size(); i++) { if (!testfun(val[i])) { **// here don't how search val[i] fails in condition** val.erase(std::remove_if(val.begin(), val.end(), val[i].id.begin()), val.end()); } } }
error: c2064: term not evaluate function taking 1 arguments
you don't have use loop loop, use following in delfun
val.erase(std::remove_if(val.begin(), val.end(), []( const sstruct2& id) { // lambda c++11 use flag -std=c++11 return ( id1.a < somevalue ) ; } val.end());
// or without lambda struct testfun { bool operator()(const sstruct2& i) const { return ( id1.a < somevalue ) ; } }; val.erase(std::remove_if(val.begin(), val.end(), testfun() val.end());
Comments
Post a Comment