SHARE
TWEET

Generic remove

ulfben Sep 26th, 2016 (edited) 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <class T>
  2. void remove(std::vector<T>& v, int pos){
  3.     std::vector<T>::iterator it = v.begin();
  4.     std::advance(it, pos);
  5.     v.erase(it);
  6. }
  7.  
  8. template <class T>
  9. void remove(std::vector<T>& v, int pos){
  10.     v.erase(v.begin()+pos);
  11. }
  12.  
  13. //or why not a swap-n-pop?
  14. template<typename T>
  15. void erase(std::vector<T>& v, int pos){
  16.     std::swap(v[pos], v.back());
  17.     v.pop_back();
  18. }
RAW Paste Data
Top