On Sunday, 19 May 2019 at 20:55:28 UTC, Josh wrote:
Just started looking at D this weekend, coming from a C++/Java/Go/Rust background and it's really not going well. Trying to write something to play with the language and need a linked list, looking in std.container you have a single or doubly linked list...great.

Now how to I iterate over it and look for a value and then modify it, and maybe insert a new element before or after that element.....After spending way to long on the API realized I need to be looking at std.range (I think, maybe not, I'm not sure).

Here's an example using std.container.dlist:

import std.stdio;
import std.container.dlist;
import std.algorithm;

void main()
{
    auto list = make!DList("the", "quick", "brown", "fox");
    auto range = list[].find("quick");
    range.front = "slow";
    list.insertBefore(range, "really");
    list[].each!writeln; // The really slow brown flox
}

Interactive version: https://run.dlang.io/is/j1Qa8y

Reply via email to