fork(2) download
  1. #include <utility>
  2. #include <type_traits>
  3. #include <iostream>
  4.  
  5. struct foo{};
  6.  
  7. template<typename T>
  8. void bar2(T&& t)
  9. {
  10. std::cout << __PRETTY_FUNCTION__ << ' '
  11. << std::is_rvalue_reference<decltype(t)>::value << '\n';
  12. }
  13.  
  14. template<typename T>
  15. void bar1(T&& t)
  16. {
  17. std::cout << __PRETTY_FUNCTION__ << ' '
  18. << std::is_rvalue_reference<decltype(t)>::value << '\n';
  19. bar2(std::forward<T>(t));
  20. bar2(t);
  21. }
  22.  
  23. int main()
  24. {
  25. foo f;
  26. bar1(f);
  27. std::cout << "--------\n";
  28. bar1(foo{});
  29. }
  30.  
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
void bar1(T&&) [with T = foo&] 0
void bar2(T&&) [with T = foo&] 0
void bar2(T&&) [with T = foo&] 0
--------
void bar1(T&&) [with T = foo] 1
void bar2(T&&) [with T = foo] 1
void bar2(T&&) [with T = foo&] 0