Correctly implementing a bidirectional range on a linked list?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 6 13:50:18 PDT 2015


How do you correctly implement a bidirectional range on a linked 
list?

I have a linked list implementation and I've added a range 
interface to it but after a while I've realized it not quite 
right. The problem is when I call the save method of the forward 
range interface I don't get a copy I only get another view to the 
same state. So when i remove nodes from the original list the 
range becomes invalid.

How can you implement such a range over a type whose state is 
accessed via pointers?

Here's my implementation:

https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection/linkedlist.d#L533


More information about the Digitalmars-d-learn mailing list