fork(1) download
  1. #include <iostream>
  2. #include <boost/type_index.hpp>
  3.  
  4. struct x{};
  5.  
  6. int main()
  7. {
  8.  
  9. x&& t = x();
  10. std::cout << "\nnaked types";
  11. std::cout << "\n l: " << std::is_lvalue_reference<x&>::value;
  12. std::cout << "\nlr: " << std::is_lvalue_reference<x&&>::value;
  13. std::cout << "\n r: " << std::is_rvalue_reference<x&>::value;
  14. std::cout << "\nrr: " << std::is_rvalue_reference<x&&>::value;
  15. std::cout << "\nlref, decltype";
  16. std::cout << "\n t: " << std::is_lvalue_reference<decltype(t)>::value;
  17. std::cout << "\n 1: " << std::is_lvalue_reference<decltype(x())>::value;
  18. std::cout << "\n m: " << std::is_lvalue_reference<decltype(std::move(t))>::value;
  19. std::cout << "\nrref, decltype";
  20. std::cout << "\n t: " << std::is_rvalue_reference<decltype(t)>::value;
  21. std::cout << "\n 1: " << std::is_rvalue_reference<decltype(x())>::value;
  22. std::cout << "\n m: " << std::is_rvalue_reference<decltype(std::move(t))>::value;
  23. std::cout << "\nlref, decltype(())";
  24. std::cout << "\n t: " << std::is_lvalue_reference<decltype((t))>::value;
  25. std::cout << "\n 1: " << std::is_lvalue_reference<decltype((x()))>::value;
  26. std::cout << "\n m: " << std::is_lvalue_reference<decltype((std::move(t)))>::value;
  27. std::cout << "\nrref, decltype(())";
  28. std::cout << "\n t: " << std::is_rvalue_reference<decltype((t))>::value;
  29. std::cout << "\n 1: " << std::is_rvalue_reference<decltype((x()))>::value;
  30. std::cout << "\n m: " << std::is_rvalue_reference<decltype((std::move(t)))>::value;
  31. std::cout << "\nexpr is lvalue";
  32. std::cout << "\n t: " << std::is_same<decltype((t)), x&>::value;
  33. std::cout << "\n 1: " << std::is_same<decltype((x())), x&>::value;
  34. std::cout << "\n m: " << std::is_same<decltype((std::move(t))), x&>::value;
  35. std::cout << "\nexpr is xvalue";
  36. std::cout << "\n t: " << std::is_same<decltype((t)), x&&>::value;
  37. std::cout << "\n 1: " << std::is_same<decltype((x())), x&&>::value;
  38. std::cout << "\n m: " << std::is_same<decltype((std::move(t))), x&&>::value;
  39. std::cout << "\nexpr is neither";
  40. std::cout << "\n t: " << std::is_same<decltype((t)), x>::value;
  41. std::cout << "\n 1: " << std::is_same<decltype((x())), x>::value;
  42. std::cout << "\n m: " << std::is_same<decltype((std::move(t))), x>::value;
  43. }
  44.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
naked types
 l: 1
lr: 0
 r: 0
rr: 1
lref, decltype
 t: 0
 1: 0
 m: 0
rref, decltype
 t: 1
 1: 0
 m: 1
lref, decltype(())
 t: 1
 1: 0
 m: 0
rref, decltype(())
 t: 0
 1: 0
 m: 1
expr is lvalue
 t: 1
 1: 0
 m: 0
expr is xvalue
 t: 0
 1: 0
 m: 1
expr is neither
 t: 0
 1: 1
 m: 0