Is there such concept of a list in D?

Ali Çehreli acehreli at yahoo.com
Sat Dec 10 15:59:07 UTC 2022


On 12/9/22 22:11, thebluepandabear wrote:

 > I was wondering more if there is an object oriented way of creating
 > arrays,

Every collection has its own special interface. Object orientation don't 
go well with collections. For example, you wouldn't want indexing 
operator for a linked list.

 > like in Java there is an `ArrayList`, in C++ there is
 > `std::vector`, etc.

They are all dynamic arrays behind the scenes.

Arrays are so much better than linked lists that linked lists don't have 
much use outside of interviews.

- Arrays use less memory

- Provide constant time element access

- Amortized constant time element addition

- Constant time element removal in some cases (move the last element in 
place of the removed one)

- Ability to sort to find elements in logN time later on

- Arrays get special help from the CPU (e.g. cache prefetches)

There isn't a single point in favor of linked lists.

Ali



More information about the Digitalmars-d-learn mailing list