Changing elements during foreach
Dicebot
public at dicebot.lv
Mon Oct 21 12:28:58 PDT 2013
On Monday, 21 October 2013 at 16:22:29 UTC, Krzysztof Ciebiera
wrote:
> 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).
void main()
{
import std.stdio;
int[][] data = [ [ 0, 1, 2], [2, 3, 4] ];
foreach(ref arr; data)
{
if (arr[0] == 2)
arr ~= 5;
}
writeln(data);
}
?
(original arrays can be also allocated with extra capacity to
avoid copy-allocation upon extending)
More information about the Digitalmars-d-learn
mailing list