std.container update

Jonathan M Davis jmdavisProg at gmail.com
Fri May 28 04:58:55 PDT 2010


> BTW, what would be the point of an array/vector when you have built-in
> arrays? If built-in arrays would be syntax sugar for a real library type,
> like AAs, I can see as a good option using Array for that type, since
> built-in arrays and the library Array would be the same thing.

The biggest difference is that a vector has capacity separate from its 
size/length. You can efficiency insert elements at the end with a vector - 
amortized constant time usually - but you can't do that with a built-in 
array because it would have to reallocate every time. D's arrays are 
fantastic, but they're still not quite good enough to outright replace a 
vector type.

On top of that, of course, there's the issue of the API used to interact 
with it, which is what we're getting with std.container, but that could 
probably be gotten around in much the same way as the range stuff was with 
std.array. Really, the big difference is that you can efficiently append to 
a vector type while you cannot do that with an array. The array is still a 
tad too low level. And since you do need that low levelness at least some of 
the time (particularly in a systems language), it's not like you could 
replace arrays with vectors or make them act more like vectors. Both types 
have their uses.

- Jonathan M Davis


More information about the Digitalmars-d mailing list