fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. template<typename X>
  6. struct thing {
  7. };
  8.  
  9. template<typename T>
  10. decltype (auto) f(T&& t) {
  11. if (std::is_same<typename std::remove_reference<T>::type, T>::value) {
  12. cout << "not ";
  13. }
  14. cout << "a reference" << endl;
  15. return std::forward<T>(t);
  16. }
  17. template<
  18. template<class> class T,
  19. typename A>
  20. decltype (auto) g(T<A>&& t) {
  21. return std::forward<T<A>>(t);
  22. }
  23.  
  24. int main(int, char**) {
  25. thing<int> it {};
  26. f(thing<int> {});
  27. f(it);
  28. // T = thing<int> &
  29. // T&& = thing<int>& && = thing<int>&
  30. g(thing<int> {});
  31. //g(it);
  32. // T = thing
  33. // A = int
  34. // T<A>&& = thing<int>&&
  35. return 0;
  36. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
not a reference
a reference