fork(5) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define FWD(a) std::forward<decltype(a)>(a)
  5. void foo(int& a) { cout << "lref" << endl; }
  6. void foo(const int& a) { cout << "cref" << endl; }
  7. void foo(int&& a) { cout << "rref" << endl; }
  8.  
  9. template <typename T>
  10. void call_foo(T&& t) { foo(FWD(t)); }
  11.  
  12.  
  13. int main() {
  14. int a = 10;
  15. call_foo(10); // 3) prints cref
  16. call_foo(a); // 4) prints cref
  17. return 0;
  18. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
rref
lref