implements unique algorithm

I always forget about std::ref :)