Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <forward_list>
  3.  
  4.  
  5. int main()
  6. {
  7. std::forward_list<int> a = {1,2,3,4,5,6};
  8.  
  9. std::forward_list<int> b;
  10.  
  11. while( !a.empty() )
  12. b.splice_after(b.before_begin(), a, a.before_begin());
  13.  
  14. for( auto i : b )
  15. {
  16. std::cout << i << std::endl;
  17. }
  18. std::cout << "---------" << std::endl;
  19. for( auto i : a )
  20. {
  21. std::cout << i << std::endl;
  22. }
  23. std::cout << "---------" << std::endl;
  24. return 0;
  25. }
  26.  
  27.  
  28. /*
  29. std::forward_list::splice_after
  30. void splice_after (const_iterator position, forward_list& fwdlst); //for entire list
  31. void splice_after (const_iterator position, forward_list& fwdlst, const_iterator i); //for single elemnt ,Iterator to an element in fwdlst preceding the one to be transferred.
  32. void splice_after (const_iterator position, forward_list& fwdlst, const_iterator first, const_iterator last); //element range The function transfers the elements in open interval range (first,last) to position.
  33.  
  34.  
  35. Transfer elements from another forward_list
  36. Transfers elements from fwdlst into the container inserting them after the element pointed by position.
  37.  
  38. This effectively inserts those elements into the container and removes them from fwdlst, altering the sizes of both containers. The operation does not involve the construction or destruction of any element. They are transferred, no matter whether fwdlst is an lvalue or an rvalue, or whether the value_type supports move-construction or not.
  39.  
  40. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement