fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. namespace thing {
  7. struct thing {
  8. int dummy;
  9. operator int (void) const {
  10. return dummy;
  11. }
  12. thing (int value) : dummy (value) {}
  13. thing (thing const & other) : dummy (other.dummy) {
  14. cout << "copy " << this << " from " << &other << endl;
  15. }
  16. thing & operator=(thing const & other) {
  17. dummy = other.dummy;
  18. cout << "assign " << this << " from " << &other << endl;
  19. }
  20. void swap (thing & other) {
  21. cout << "ms " << this << " and " << &other << endl;
  22. internal_swap (other);
  23. }
  24. void internal_swap (thing & other) {
  25. auto temp = dummy;
  26. dummy = other.dummy;
  27. other.dummy = dummy;
  28. }
  29. };
  30.  
  31. void swap (thing & lhs, thing & rhs) {
  32. cout << "fs " << &lhs << " and " << &rhs << endl;
  33. lhs.internal_swap(rhs);
  34. }
  35. }
  36.  
  37. int main() {
  38. vector<thing:: thing> data = {1, 21, 42};
  39. cout << "sorting now" << endl;
  40. sort (begin (data), end (data), greater<int>{});
  41. return 0;
  42. }
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
copy   0x9cbda10 from 0xbfb5bbb4
copy   0x9cbda14 from 0xbfb5bbb8
copy   0x9cbda18 from 0xbfb5bbbc
sorting now
copy   0xbfb5bb6c from 0x9cbda14
assign 0x9cbda14 from 0x9cbda10
assign 0x9cbda10 from 0xbfb5bb6c
copy   0xbfb5bb6c from 0x9cbda18
assign 0x9cbda18 from 0x9cbda14
assign 0x9cbda14 from 0x9cbda10
assign 0x9cbda10 from 0xbfb5bb6c