Hi,
Reading Marco Cantu’s book on Object Pascal, I got to the description of dynamic arrays concatenation and adding unitary elements into them. It is probably nothing new for the most of people here, but I realized this also works in FPC 3.2:
program dyn_array_tricks;
{$mode objfpc} {$H+} {$modeSwitch arrayOperators+}
uses
SysUtils;
var
da: array of byte;
i, k: byte;
BEGIN
da := [1, 2, 3];
da := da + da;
//da := Concat(da,da); does the same as above
da := da + [4, 5];
k := 99;
da := da + [k];
for i in da do
Writeln(i.ToString);
//Writeln(IntToStr(i)); does the same as above
END.
On the very first look it seems like a very cool feature, but then I tried to think of a possible application of it. This approach is probably not very fast as (I guess) it uses array resizing (like SetLength) at before addition of new elements and therefore there is not much sense in putting it into a loop. So far I have come up with only one example, when one needs to iteratively compute some value (an integral, etc) with a pre-set accuracy and would like to keep track of the whole trajectory. So at each iteration (of unknown number of course) it is possible to add the values of some parameters into an array to see later how the changed.
So I have two questions on this set of features:
1) What would be an “ideal”, but real life example of using these dynamic arrays features?
2) Isn’t this anything similar (or even based on) to the TVector type from RTL? As far as I can see it is capable of doing (almost?) exactly the same things.
Thank you.