On Monday, 13 February 2023 at 18:04:40 UTC, Matt wrote:
Obviously, there is no "set" object in D, but I was wondering what the quickest way to remove duplicates from an array would be...

Where did you find out that there is no set() in the D programming language?

**Simple example:**

```d
import std;

auto str = "D Programming Language";

void main()
{
  size_t i;
  str.map!(n => tuple(n, i++))
     .assocArray.keys
     .sort.writeln; // DLPaegimnoru
}
```

**X-Ray example:**
```d
auto set(R)(R[] list) {
  size_t[R] result;
  foreach(i, item; list) {
    result[item] = i;
  }
  return result.keys;
}

unittest
{
  auto xRay = set(str.dup);
  xRay.array.sort.writeln; // DLPaegimnoru
}
```

SDB@79

Reply via email to