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