In the following code,
#include <utility>
struct literal_type
{
// ...
};
class my_type
{
public:
my_type(literal_type const& literal); // (1)
my_type(literal_type && literal); // (2)
// ...
};
void foo()
{
literal_type literal_var { /* ... */ };
my_type var1 (literal_var); // Calls (1)
my_type var2 (std::move(var)); // Calls (2)
my_type var3 (literal_type{}); // Calls (2)
}
I understand that the value category of the argument passed in the constructor of var1 is an l-value, var2 is an x-value and var3 is a pr-value.
I would like that the constructor of my_type accepts var3, while var1 and var2 should emit a compiler error. var1 is easily solved by removing constructor (1), but I cannot find the way to distinguish between var2 and var3.
Is there any way to distinguish between x-value references and pr-value references?