ulfben

Generic remove

Sep 26th, 2016
613
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  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. }
Advertisement
Comments
  • Rteuixl
    217 days
    # text 0.21 KB | 0 0
    1. Best t33n active cpx link daily updates!
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
    6.  
    7. Remove the @
  • Comment was deleted
Add Comment
Please, Sign In to add comment