How can I make a function that prints the value category using decltype?


This works for the expression rvalueRef++, but I have to put the 3 part if:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
auto&& rvalueRef = i(8.8);
rvalueRef++;

if constexpr (std::is_lvalue_reference_v<decltype((rvalueRef++))>)
{
          cout << "Expression is lvalue\n";
}
else if constexpr (std::is_rvalue_reference_v<decltype((rvalueRef++))>)
{
	cout << "Expression is xvalue\n";
}
else
{
	cout << "Expression is prvalue\n";
}


What I am looking is a function that could do report category based on the receiving argument, something like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
template<typename T>
void printCategory(T&& t)
{
	if constexpr (std::is_lvalue_reference_v<decltype(std::forward<T>(t))>)
	{
		cout << "Expression is lvalue\n";
	}
	else if constexpr (std::is_rvalue_reference_v<decltype(std::forward<T>(t))>)
	{
		cout << "Expression is xvalue\n";
	}
	else
	{
		cout << "Expression is prvalue\n";
	}
}


When calling this function with rvalueRef++ I get that t is an xvalue but if I place it in the three part if above directly, then I get that it is a prvalue (as it should)...


Any suggestions?

Regards,
Juan
Topic archived. No new replies allowed.