fork download
  1. #include <iostream>
  2. using namespace std;
  3. void foo_no_template(int &&y) {
  4. y = 1500;
  5. cout << "foo_no_template's y :" << y << endl;
  6. }
  7. template<class T>
  8. void foo(T &&y) {
  9. y = 500;
  10. cout << "foo's y :" << y << endl;
  11. }
  12. template<class T>
  13. void bar(T &&y) {
  14. foo(move(y));
  15. cout << "bar's y after foo :" << y << endl; // prints 500
  16. foo_no_template(move(y));
  17. cout << "bar's y after foo no template:" << y << endl; // prints 1500
  18. }
  19. int main()
  20. {
  21. bar(10);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
foo's y :500
bar's y after foo :500
foo_no_template's y :1500
bar's y after foo no template:1500