fork download
  1. #include <iostream>
  2.  
  3. void g(int && v1, int & v2)
  4. {
  5. std::cout << v1 << " " << ++v2 << std::endl;
  6. }
  7.  
  8. template <typename F, typename T1, typename T2>
  9. void flip(F f,T1 && t1, T2 && t2){
  10. g(t2, t1);
  11. }
  12.  
  13. int main() {
  14. int i = 1, j = 1;
  15.  
  16. g(12, i); // f changes i
  17. std::cout << "i = " << i << ", j = " << j << std::endl;
  18.  
  19. flip(g, j, 2);
  20. std::cout << "i = " << i << ", j = " << j << std::endl;
  21.  
  22. return 0;
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'void flip(F, T1&&, T2&&) [with F = void (*)(int&&, int&); T1 = int&; T2 = int]':
prog.cpp:19:14:   required from here
prog.cpp:10:13: error: cannot bind 'int' lvalue to 'int&&'
     g(t2, t1);
             ^
prog.cpp:3:6: note: initializing argument 1 of 'void g(int&&, int&)'
 void g(int && v1, int & v2)
      ^
stdout
Standard output is empty