This may be obvious but I think it is something difficult to me. Given this:
void test(std::string&&) { } std::string x{"test"}; test(std::move(x)); // ok This code calls test() with a rvalue reference as parameter so the program compiles as I expect.
Now look at this:
void other_test(const std::string&) { } std::string x{"test"}; other_test(std::move(x)); // ok??? And here I'm tilted. Why does this version compile? The std::move returns a && type; why then I don't get an error in the second method where I use const&?
I know that
int&& s = 5; const int& s = 5; is valid because in both cases I provide something that has not an lvalue, it has no addresses. Are && and const& equivalent? If no, are there differences?
const&bind to an rvalue when I expect it to fail?"void test(std::string&& a)andvoid test(const std::string& a)both in scope when you do your tests?