automate tuple creation

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 21 21:56:33 UTC 2022


On Fri, Jan 21, 2022 at 09:43:38PM +0000, forkit via Digitalmars-d-learn wrote:
> On Friday, 21 January 2022 at 21:01:11 UTC, forkit wrote:
[...]
> even better, I got rid of all those uncessary arrays ;-)
> 
> // ---
> 
> int[][int][] CreateDataSet
> (const(int) recordsNeeded, const(int)valuesPerRecord)
> {
>     int[][int][] records;
>     records.reserve(recordsNeeded);
> 
>     foreach(i, id; iota(iotaStartNum, iotaStartNum +
> recordsNeeded).enumerate)
>     {
>         records ~= [ id: iota(valuesPerRecord).map!(valuesPerRecord =>
> cast(int)rnd.dice(0.6, 1.4)).array ];
>     }
> 
>     return records.dup;

What's the point of calling .dup here?  The only reference to records is
going out of scope, so why can't you just return it?  The .dup is just
creating extra work for nothing.


T

-- 
Unix was not designed to stop people from doing stupid things, because that would also stop them from doing clever things. -- Doug Gwyn


More information about the Digitalmars-d-learn mailing list