De-duplicating a range that's not necessarily sorted seems to be a
pretty common task, so here's a generic function for whoever else might
want to do this:

        import std.range.primitives;

        auto deduplicate(R)(R range)
                if (isInputRange!R)
        {
                import std.algorithm : filter;
                alias E = ElementType!R;
                bool[E] seen;
                return range.filter!((e) {
                        if (e in seen) return false;
                        seen[e] = true;
                        return true;
                });
        }


T

-- 
Why have vacation when you can work?? -- EC

Reply via email to