fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <stdexcept>
  7. #include <initializer_list>
  8.  
  9. using namespace std;
  10.  
  11. const string& f(const string &s1, const string &s2)
  12. {
  13. return s1.size() < s2.size() ? s1 : s2;
  14. }
  15.  
  16. string& f(string &s1, string &s2)
  17. {
  18. auto ret = f(const_cast<const string&>(s1), const_cast<const string&>(s2));
  19. return const_cast<string&>(ret);
  20. }
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24. string x = "xxxxxx";
  25. string y = "yyy";
  26.  
  27. string &z = f(x, y);
  28.  
  29. cout << z << endl;
  30.  
  31. cout << z << y << endl;
  32. }
  33.  
Runtime error #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty