Generic remove

Sep 26th, 2016
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. }
  8. template <class T>
  9. void remove(std::vector<T>& v, int pos){
  10.     v.erase(v.begin()+pos);
  11. }
  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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.