Empty non-null Associative Arrays should be trivial or even the default.
Mike Parker
aldacron at gmail.com
Tue Aug 3 16:46:13 UTC 2021
On Tuesday, 3 August 2021 at 16:28:03 UTC, Rekel wrote:
>
> Also a small sidequestion; how come remove is part of AA's
> definition while the removal of items from dynamic lists is
> part of the library instead?
>
AAs have to do internal bookkeeping, with the buckets and such,
that dynamic arrays do not have to worry about. So they've had
their own remove function from the beginning.
As I recall, dynamic arrays didn't have a remove function back in
the D1 days. Removal was a matter of iteration and slicing:
```d
foreach(i, e; arr)
{
if(e == toRemove)
{
arr = a[0 .. i] ~ a[i+1 .. $];
break;
}
}
```
And the remove function we have now is not specifically for
dynamic arrays. It's for ranges. Dynamic arrays happen to be
ranges (courtesy of the range API implemented for them in
std.array) so you can use them with that function and any
function in std.algorithm.
Static arrays and associative arrays are not ranges.
More information about the Digitalmars-d
mailing list