fork download
  1. #include <iostream>
  2. #include <stdexcept>
  3. struct Foo
  4. {
  5. Foo(const Foo&) { std::cout << "Foo(const Foo&)\n";}
  6. Foo(Foo&&) { std::cout << "Foo(Foo&&)\n";}
  7. Foo() { std::cout << "Foo()\n";}
  8. Foo& operator=(const Foo&) {
  9. std::cout << "operator=(const Foo&)\n";
  10. return *this;
  11. }
  12. Foo& operator=(Foo&&) {
  13. std::cout << "operator=(Foo&&)\n";
  14. return *this;
  15. }
  16. };
  17.  
  18. Foo foo(int i)
  19. {
  20. if (i<0)
  21. {
  22. throw std::out_of_range("Foo fail!");
  23. }
  24. else
  25. {
  26. return Foo();
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. Foo f = foo(1);
  33. }
  34.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
Foo()