The code is attach as follow. i tried to implement a method to check the expression or varible's value type. but it seems failed to check rvalue.
#include <iostream>
#include <type_traits>
#include <vector>
#include <string>
template <typename T>
void checkLValueRValue(T&& value) {
using Type = decltype(std::forward<T>(value));
if (std::is_lvalue_reference<Type>::value) {
std::cout << "It's an lvalue reference." << std::endl;
} else if (std::is_rvalue_reference<Type>::value) {
std::cout << "It's an rvalue reference." << std::endl;
} else {
std::cout << "It's not an lvalue or rvalue reference." << std::endl;
}
}
class A {
};
int main() {
int x = 42;
int y = 43;
int& lvalue_ref = x;
int&& rvalue_ref = std::move(x);
std::cout << std::is_rvalue_reference_v<A&&> << std::endl;
checkLValueRValue(x); // lvalue reference
checkLValueRValue(lvalue_ref); // lvalue reference
checkLValueRValue(std::move(x));// rvalue reference
*checkLValueRValue(rvalue_ref); // it should be rvalue reference but not!*
return 0;
}
the last checkLValueRvalue outputs It's an lvalue reference ? what happened ?
i am new to cpp, so i don't get it.