Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. value&
  2. value::
  3. operator=(value const& other)
  4. {
  5. struct undo
  6. {
  7. union
  8. {
  9. value v;
  10. };
  11. value* pv;
  12. bool commit = false;
  13.  
  14. explicit
  15. undo(value* pv_)
  16. : pv(pv_)
  17. {
  18. relocate(&v, *pv);
  19. }
  20.  
  21. ~undo()
  22. {
  23. if(commit)
  24. v.~value();
  25. else
  26. relocate(pv, v);
  27. }
  28. };
  29.  
  30. if(this != &other)
  31. {
  32. undo u(this);
  33. copy(other,
  34. u.v.get_storage());
  35. u.commit = true;
  36. }
  37.  
  38. return *this;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement