View difference between Paste ID: dFAB96Zb and xnbGgSKz
SHOW: | | - or go back to the newest paste.
1
template<typename it>
2
it yourUnique(it begin, it end){
3
    typedef typename std::iterator_traits<it>::value_type value_t;
4
    typedef std::pair<value_t,int> pair_t;
5
6
    vector<pair_t> v;
7
    for(it c = begin; c != end; ++c){
8
        v.push_back(make_pair(*c, v.size())); // second is start index;
9
    }
10
    sort(v.begin(), v.end()); // sort by value then by index
11
    v.erase(unique(v.begin(), v.end(), firstEqual<value_t>), v.end());
12-
    stable_sort(v.begin(), v.end(), bySecond<value_t>); // restore order.
12+
    sort(v.begin(), v.end(), bySecond<value_t>); // restore order.
13
    it c = begin;
14
15
    for(const auto& x: v){
16
       *(c++) = x.first;
17
    }
18
    return c;
19
}