Simplest way to convert an array into a set

Salih Dincer salihdb at
Tue Feb 14 01:26:16 UTC 2023

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:**

import std;

auto str = "D Programming Language";

void main()
   size_t i;!(n => tuple(n, i++))
      .sort.writeln; // DLPaegimnoru

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

   auto xRay = set(str.dup);
   xRay.array.sort.writeln; // DLPaegimnoru

SDB at 79

More information about the Digitalmars-d-learn mailing list