You might say that I should be fine with
std::is_lvalue_reference<T>::value
But the problem appears when string literals come in a question. As what I have read, string literals are treated as const char*, which is evaluated as an lvalue. How to ensure that a string literal will be treated as an rvalue?
Assume following non-existing code.
template <typename T>
inline static void f(T&& arg) {
static_assert(my_lvalue_traits<T>::value, "Only lvalue permitted") ;
// Some code.
}
How should my_lvalue_traits look like if i want to achieve these results?
std::string x;
f(x); // Everything OK, the argument is an lvalue.
int y;
f(y); // Everything OK, the argument is an lvalue.
f("some literal"); // Static assertion failure. I want string literal to behave as an rvalue.
f(5); // Static assertion failure. Argument is an rvalue.
Please note that I want to use this traits in a variadic templated class, so this might not be a perfect example. Something like
f(std::string("some literal"));
is not a solution, too.