Guest User

Untitled

a guest
Oct 25th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. std::string line; // cannot be const
  2. std::getline(std::cin, line);
  3. // line should be const from here on out
  4.  
  5. std::string f1();
  6. std::string f2(std::string s);
  7. std::string f3() {
  8. const std::string s = f1(); // s is not meant to be modified
  9. // but I still want the move optimization here:
  10. const std::string result = f2(std::move(s)); // this doesn't move
  11. // and I want the compiler to move out here:
  12. return result; // this will probably RVO, but if not, the move
  13. // constructor will not be used due to the const
  14. }
Add Comment
Please, Sign In to add comment