vendredi 21 août 2015

How to delete elements by key in map, which contains char and pair

I want to delete all elements which pair first == 0

Here code:

int main()
{
    map<char, pair<int,string>> myMap;
    map<char, pair<int,string>>::const_iterator it;
    for (int i = 0; i < 10; i++)
    {
        char c = 'a' + i;
        pair<int,string> p = make_pair(rand() % 2, "dd");
        myMap.insert(make_pair(c,p));
    }

    it = find_if(myMap.begin, myMap.end(), isEqual);

}

bool isEqual(const pair<int, string> element)
{
    return element.first == 0;
}

Is there any way to do it using find_if?

Aucun commentaire:

Enregistrer un commentaire