uniq and array of enum members (That are all strings)

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jan 16 18:20:57 UTC 2019


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


More information about the Digitalmars-d-learn mailing list