My code:
#include <string>
#include <utility>
#include <iostream>
void store(std::string & val)
{
std::cout << "lvalue " << val << '\n';
}
void store(std::string && val)
{
std::cout << "rvalue " << val << '\n';
}
template<typename T> void print(T && val)
{
std::cout << std::boolalpha << std::is_lvalue_reference<T>::value << " ";
store(std::forward<T>(val));
}
int main()
{
std::string val("something");
print(val);
print("something else");
}
my output:
true lvalue something
true rvalue something else
I've read on Universal referencing and understand why T is a lvalue when the input is a lvalue but I don't understand how is T a lvalue when the input is a rvalue, how does that collapse to the right paramter?