Grokking std.container and Ranges

Rory McGuire rmcguire at neonova.co.za
Tue Jun 29 01:33:39 PDT 2010


On Tue, 29 Jun 2010 07:16:13 +0200, BCS <none at anon.com> wrote:

> Hello Mike,
>
>> I want to do the following:
>> foreach(obj; list)
>> {
>> if(obj.pleaseKillMe)
>> somehow_remove_the_object_from_the_list();
>> }
>
> That isn't legal for normal arrays or AAs. IIRC the docs even say that  
> you can't change what a foreach is iterating over during the foreach. I  
> think you will have to convert to a manual for loop to make it work.  
> That said, I've not worked with range at all.
>

Perhaps keep the foreach and make a list of to be deleted objects and then  
delete them after the foreach.


More information about the Digitalmars-d-learn mailing list