Guest User

Untitled

a guest
Jan 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. //
  2. // Created by Barthap on 2019-01-22.
  3. //
  4.  
  5. #include <utility>
  6. #include <iostream>
  7. #include <vector>
  8. #include <list>
  9.  
  10. int main()
  11. {
  12. std::list<int> lista = {1,2,3,4,5};
  13. for(auto& e : lista)
  14. std::cout << e << " ";
  15. std::cout << std::endl;
  16.  
  17. auto it = std::find(lista.begin(), lista.end(), 4);
  18. int &ref = *it;
  19.  
  20. std::cout << "ref = " << ref << std::endl;
  21.  
  22. //std::remove_if(lista.begin(), lista.end(), [](auto& el) { return el == 2; });
  23. lista.remove_if([](auto& el) { return el == 2; });
  24.  
  25. std::cout << "after remove, ref = " << ref << std::endl;
  26.  
  27. auto it2 = std::find(lista.begin(), lista.end(), 4);
  28. std::cout << "Original address: " << std::addressof(ref)
  29. << "\nAfter remove: " << std::addressof(*it2) << std::endl;
  30.  
  31. ref = 16;
  32.  
  33. for(auto& e : lista)
  34. std::cout << e << " ";
  35. std::cout << std::endl;
  36. }
Add Comment
Please, Sign In to add comment