I cannot find any good documentation on how to use a range in conjunction with a container. I’m trying to insert an element into a SList using the given .insertAfter() function. It takes a range though and I have no idea how to retrieve it.
Can someone please post an example or two of how to use this poorly documented feature?
This is the D documentation for containers – http://dlang.org/phobos/std_container.html
I’ve also read ranges can be used like c++ iterators. If this is true how can I use a range in a loop?
use the slice operator (
[])to get the range of a containerto iterate over a container you can do:
a range has a front property which is the element currently pointed at, the popFront of a range will move the range to the next element and empty will indicate whether the range is at the end
the foreach loop above is equivalent to
to insert into the middle of the list you’ll need to do
to insert at the end it’s