sortUniq

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 24 06:53:35 PST 2015


On 1/24/15 4:13 AM, zeljkog wrote:
> On 24.01.15 12:50, Peter Alexander wrote:
>> auto f = unique();
>> [1, 5, 5, 2, 1, 5, 6, 6].filter!(f).writeln;  // [1, 5, 2, 6]
>>
>> Filter needs an alias, and you cannot alias an R-value (it has no symbol).
>
> Yes, I see :)
>
> But I think this should be supported by std.algorithm:
>
> import std.stdio, std.algorithm;
>
> struct Uniq{
>      bool[int] c;
>      bool opCall(int a){
>          if (a in c)
>              return false;
>          else{
>              c[a] = true;
>              return true;
>          }
>      }
> }
>
> void main()
> {
>      [1, 5, 5, 2, 1, 5, 6, 6].filter!Uniq.writeln;
> }

I can't make sense of this - where is Uniq supposed to be instantiated? 
-- Andrei



More information about the Digitalmars-d mailing list