The reason you're having the problem is that std::for_each is meant to traverse the entire range you supply to it and not break. If you really want something to be able to terminate early you can do it with std::find_if provided you change your lambda to be a boolean predicate (which is a fairly trivial change):
[&id, &updateRecord](Record & record)->bool
{
if( record.get_record().find(id) == 2 )
{
record.set_record(updateRecord);
return true;
}
return false;
}
You might want to rename find_if as well to show that you're not actually trying to find something, just iterating until a condition.
Cheers,
Ash
Edit: Such a trivial change that I messed it up!