Dynamic arrays in D 1.0

Edward Diener eddielee_no_spam_here at tropicsoft.com
Mon May 12 20:30:01 PDT 2008


boyd wrote:
> I think it's because erase and insert are really just the inverse of 
> slicing and concatenation.
> 
> int[] a, c;
> 
> // insert
> c = a.insert(b, 10);
> c = a[0..10] ~ b ~ a[10..$];
> 
> // delete
> c = a.delete(&a[10..20]);
> c = a[0..10] ~ a[20..$];
> 
> I essence delete and insert are just another way of expressing slices 
> and concatenations. Personally I prefer slicing and concatting stuff, 
> because it expresses better what's actually happening.
> 
> Delete and Insert on the other hand are higher level and generally more 
> intuitive. They leave optimization to the compiler/library. And I think 
> most D-users like more control of optimizations than users of more high 
> level languages.

You make a good point that things like delete, insert, and replace can 
be done with slicing and concatentaion. Thanks for bringing up these 
solutions. Having used Python extensively, where slicing is also a big 
part of lists, I should have realized that such operations are largely 
subsumed by slicing and concatenation in D. I have to take my C++ hat 
off and put my Python hat one when dealing with dynamic arrays in D.



More information about the Digitalmars-d mailing list