fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void only_accepts_rvalues(string&& name)
  5. {
  6. cout << name << endl;
  7. }
  8.  
  9. int main() {
  10. // this doesn't compile
  11. string name{"banachtarski"};
  12. only_accepts_rvalues(name);
  13.  
  14. // This does
  15. only_accepts_rvalues(std::move(name));
  16. return 0;
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:12:27: error: cannot bind 'std::string {aka std::basic_string<char>}' lvalue to 'std::string&& {aka std::basic_string<char>&&}'
  only_accepts_rvalues(name);
                           ^
prog.cpp:4:6: note:   initializing argument 1 of 'void only_accepts_rvalues(std::string&&)'
 void only_accepts_rvalues(string&& name)
      ^
stdout
Standard output is empty