fork download
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct X {
  6. int i;
  7. X(int i_): i(i_) { cout << "X(): " << i << endl; }
  8. X(const X&x): i(x.i) { cout << "X(const X&): " << x.i << endl; }
  9. X(X&&x): i(x.i) { cout << "X(X&&x): " << x.i << endl; }
  10. };
  11. X ternary(bool cond) {
  12. X a(1);
  13. X b(2);
  14.  
  15. return cond ? a : b;
  16. }
  17. X ifelse(bool cond) {
  18. X a(1);
  19. X b(2);
  20.  
  21. if(cond) return a; else return b; // uses
  22. }
  23. int main() {
  24. X v = ternary(true);
  25. X w = ifelse(true);
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
X():       1
X():       2
X(const X&): 1
X():       1
X():       2
X(X&&x):   1