How to store unique values of array in another array

Samir samir at aol.com
Thu Oct 18 18:39:18 UTC 2018


What is the proper way to find the unique values of an array and 
store them in another array?  When I try:

import std.stdio: writeln;
import std.conv;
import std.algorithm;

void main() {
     int[] unsortedArray = [5, 3, 8, 5, 2, 3, 0, 8];
     int[] uniqueArray;

     uniqueArray = uniq(sort(unsortedArray));
}

I get the compilation error:
sortSetUnique2.d(9): Error: cannot implicitly convert expression 
uniq(sort(unsortedArray)) of type UniqResult!(binaryFun, 
SortedRange!(int[], "a < b")) to int[]

which leads me to believe that the output of `uniq` is not 
necessarily another integer array.

Thanks


More information about the Digitalmars-d-learn mailing list