fork download
  1. #include <iostream>
  2.  
  3. class Foo {
  4. public:
  5. Foo() = default;
  6.  
  7. Foo(const Foo&) = default;
  8. Foo(Foo&&) noexcept = default;
  9.  
  10. Foo& operator=(const Foo& rhs) & {
  11. std::cout << "copy\n";
  12.  
  13. return *this;
  14. }
  15.  
  16. Foo& operator=(Foo&& rhs) & noexcept {
  17. std::cout << "move\n";
  18.  
  19. return *this;
  20. }
  21.  
  22. Foo operator+(const Foo& rhs) const {
  23. Foo x; // with some calculation
  24.  
  25. return x;
  26. }
  27. };
  28.  
  29. int main() {
  30. Foo a, b, c;
  31.  
  32. a = b + c;
  33. }
Success #stdin #stdout 0s 4536KB
stdin
Standard input is empty
stdout
move