Removing elements that match a specified criterium from a vector

Deleting items that match a specific criterium from a C++ vector is not as straightforward as it seems. The solution? First define a function that determines if the element should be deleted:

bool bla(child_t &child)
{
        return child.first == -1;
}

And then use our friends erase and remove_if:

std::vector<child_t> children;
children.erase(remove_if(children.begin(), children.end(), bla), children.end());

Easy right….:)