Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename it>
- it yourUnique(it begin, it end){
- typedef typename std::iterator_traits<it>::value_type value_t;
- typedef std::pair<value_t,int> pair_t;
- vector<pair_t> v;
- for(it c = begin; c != end; ++c){
- v.push_back(make_pair(*c, v.size())); // second is start index;
- }
- sort(v.begin(), v.end()); // sort by value then by index
- v.erase(unique(v.begin(), v.end(), firstEqual<value_t>), v.end());
- sort(v.begin(), v.end(), bySecond<value_t>); // restore order.
- it c = begin;
- for(const auto& x: v){
- *(c++) = x.first;
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement