Changing elements during foreach
Krzysztof Ciebiera
ciebie at mimuw.edu.pl
Mon Oct 21 09:22:28 PDT 2013
On Monday, 21 October 2013 at 14:59:54 UTC, Alexandr Druzhinin
wrote:
> If you switch instruction order you create local copy and then
> set x[0] in local copy so original is unchanged. But local copy
> creating depends on several thing and happens not every
> appending in general. Your way is not D-ish one. What do you
> want to do?
I have an array of solutions to a problem. Each solution is an
array of elements (not numbers, but objects of some classes).
What I want to do is: I want to take a look at every single
solution and extend it if it is possible (eg. if solution
contains obbects a,b,c it can also contain d). The whole thing is
rather big so I don't want to have any nice functional-style
solution which will involve copying data. Especially since I have
to perform similar extensions over and over again.
I understand slices now and I don't find it consistent with "no
shoot in the foot by default" statement.
--
KC
More information about the Digitalmars-d-learn
mailing list