WhiZTiM

Produce Unique

Jan 6th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. template<typename Container>
  2. Container produce_unique(Container c){
  3.     Container rtn;
  4.     std::sort(c.begin(), c.end());
  5.     std::unique_copy(c.begin(), c.end(), std::back_inserter(rtn));
  6.     return rtn;
  7. }
  8.  
  9. template<typename Container, typename T = typename Container::value_type>
  10. Container produce_unique2(const Container& c){
  11.     Container rtn;
  12.     std::unordered_set<T> st;
  13.     std::copy_if(c.begin(), c.end(), std::back_inserter(rtn), [&st](const T& t){ return st.insert(t).second; });
  14.     return rtn;
  15. }
Add Comment
Please, Sign In to add comment