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