fork(1) download
  1. struct sfinae_one { char a[1]; };
  2. struct sfinae_two { char a[2]; };
  3.  
  4. const char* get_value_description(int is_glvalue, int is_rvalue)
  5. {
  6. if (is_glvalue == sizeof (sfinae_one)) return "prvalue";
  7. if (is_rvalue == sizeof (sfinae_one)) return "lvalue";
  8. return "xvalue";
  9. }
  10.  
  11. template<typename T>
  12. sfinae_one SFINAE_test_1( const T& t );
  13. template<typename T>
  14. sfinae_two SFINAE_test_1( T& t );
  15.  
  16. template<typename T>
  17. sfinae_one SFINAE_test_2( const T& t );
  18. template<typename T>
  19. sfinae_two SFINAE_test_2( T&& t );
  20.  
  21. #define VALUE_CAT(expr) get_value_description(sizeof SFINAE_test_1((expr)), sizeof SFINAE_test_2((expr)))
  22.  
  23. #include <iostream>
  24. using namespace std;
  25. int main()
  26. {
  27. int x;
  28.  
  29. cout << VALUE_CAT(x) << endl; // prints lvalue
  30. cout << VALUE_CAT(move(x)) << endl; // prints xvalue
  31. cout << VALUE_CAT(42) << endl; // prints prvalue
  32. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
xvalue
prvalue
prvalue