On Mon, 17 May 2010 11:02:05 -0400, Ellery Newcomer <ellery-newco...@utulsa.edu> wrote:

On 05/14/2010 08:20 AM, Steven Schveighoffer wrote:
Currently, D supports the special symbol $ to mean the end of a
container/range.

However, there is no analogous symbol to mean "beginning of a
container/range". For arrays, there is none necessary, 0 is always the
first element. But not all containers are arrays.

I'm running into a dilemma for dcollections, I have found a way to make
all containers support fast slicing (basically by imposing some
limitations), and I would like to support *both* beginning and end symbols.

Currently, you can slice something in dcollections via:

coll[coll.begin..coll.end];


-Steve

Does your collections library allow for code like

coll[coll.begin + 1 .. coll.end]

No. begin and end return cursors, which are essentially non-movable pointers.

The only collection where adding an integer to a cursor would be feasible is ArrayList, which does support slicing via indexes (and indexes can be added/subtracted as needed).

Note, I'm not trying to make slicing dcollections as comprehensive as slicing with arrays, I'm just looking to avoid the verbosity of re-stating the container's symbol when specifying the beginning or end. In all dcollections containers, one can always slice where one of the endpoints is begin or end.

I probably should at least add opDollar to ArrayList...

-Steve

Reply via email to