#include <numeric>
#include <vector>
#include <set>
#include <iostream>
struct IndirectCompare {
    bool operator()(int* p1, int* p2) const { return *p1 < *p2; }
};
std::vector<int> uniquefy(std::vector<int> v)
{
    // build a set of pointers, using custom comparer
    std::set<int*, IndirectCompare> s;
    for(auto i = v.begin(); i!=v.end(); ++i) // for(int& n : v)
        while(!s.insert(&*i).second)
            *i = rand() % 100;
    return v;
}
int main()
{
   std::vector<int> in = {1,12,8,1,7,15,20,9,12};
   for(size_t n = 0; n != in.size(); ++n)
       std::cout << in[n] << ' ';
   std::cout << '\n';
   std::vector<int> out = uniquefy(in);
   for(size_t n = 0; n!= out.size(); ++n) // for(int n : out)
       std::cout << out[n] << ' ';
   std::cout << '\n';
}
