Double ended arrays?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Oct 7 08:45:37 UTC 2017


On Saturday, October 07, 2017 07:38:47 Chirs Forest via Digitalmars-d-learn 
wrote:
> I have some data that I want to store in a dynamic 2d array...
> I'd like to be able to add elements to the front of the array and
> access those elements with negative integers as well as add
> numbers to the back that I'd acess normally with positive
> integers. Is this something I can do, or do I have to build a
> container to handle what I want?

Dynamic arrays only support concatenating to the end, and they use size_t
for indices and length, and size_t is unsigned. The standard library does
the same with any containers that it has as do most 3rd party libraries.

You'll need to either implement what you want yourself or use something from
somewhere like code.dlang.org. Based on Ilya's post, it sounds like you may
be able to use Mir for what you want, but I'd be very surprised to see any
libraries use negative indices for anything - especially since most
everything uses size_t for indices.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list