fork(1) download
  1. #include <cstring>
  2. #include <iostream>
  3.  
  4. template <size_t Size>
  5. void foo_array( const char (&data)[Size] )
  6. {
  7. std::cout << "named\n";
  8. }
  9.  
  10. template <size_t Size>
  11. void foo_array( char (&&data)[Size] ) //rvalue of arrays?
  12. {
  13. std::cout << "temporary\n";
  14. }
  15.  
  16.  
  17. struct A {};
  18.  
  19. void foo( const A& a )
  20. {
  21. std::cout << "named\n";
  22. }
  23.  
  24. void foo( A&& a )
  25. {
  26. std::cout << "temporary\n";
  27. }
  28.  
  29. template <typename T>
  30. struct identity {
  31. typedef T type;
  32. };
  33.  
  34. int main( /* int argc, char* argv[] */ )
  35. {
  36. A a;
  37. const A a2 = {};
  38.  
  39. foo(a);
  40. foo(A()); //Temporary -> OK!
  41. foo(a2);
  42.  
  43. //------------------------------------------------------------
  44.  
  45. char arr[] = "hello";
  46. const char arr2[] = "hello";
  47.  
  48. foo_array(arr);
  49. foo_array(identity<char[2]>::type{1,2});
  50. foo_array(arr2);
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
named
temporary
named
named
temporary
named