I have a vector of maps:
typedef map<string, string> aMap;
typedef vector<aMap> rVec;
rVec rows;
How can I remove some elements from rows?
The following code does not work.
struct remove_it
{
bool operator() (rVec& rows)
{
// Validation code here!
}
};
rVec::iterator it = remove(rows.begin(), rows.end(), remove_it());
rows.erase(it, rows.end());
I got the following error.
error: no matching function for call to 'remove(std::vector<s
td::map<std::basic_string<char>, std::basic_string<char> > >::iterator, std::vec
tor<std::map<std::basic_string<char>, std::basic_string<char> > >::iterator, mai
n(int, char**)::remove_it)'
Thanks.
1) First off: please provide a single compilable example.
Your code posted above is problematic as rVec and rowsVector have been interchanged (you would have seen that yourself if you had posted real code).
2) You are using the wrong remove. It should be remove_if
3) It is normal for the functor to be const
4) The operator() should get object of type aMap (as that is what is in your vector) not a reference back to the vector.
5) Don’t be lazy add std:: in-front of objects in the standard namespace.
rather than using
using namespace std;