On Aug 8, 2011, at 10:21 AM, Chad Rosier wrote:

>> 
>> Unless there's something non-obvious (which could be commented, if
>> that's the case) you could use the iterator returned by erase:
>> 
>> for (iterator it = begin(), ie = end(); it != ie; ) {
>> if ((*it)->getOption().matches(Id)) {
>>   it = Args.erase(it);
>> } else {
>>   ++it;
>> }
>> }
> 
> I committed the above in revision 137051.  The args list should be relatively 
> short, so this solution is good.

David,
I ran into another case where such a loop was useful.  However, using code 
similar to the above 
resulted in an infinite loop in this case.  After the Args.erase(it) I believe 
it is necessary to update ie.

Something like this:

for (InputList::iterator it = Inputs.begin(), ie = Inputs.end(); it != ie;) {
  if (types::getPreprocessedType(it->first) == types::TY_INVALID) {
    it = Inputs.erase(it);
    ie = Inputs.end();
  } else
    ++it;
}

 Chad
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to