I have the following code, and I can move unique pointer variable several times.
Why is it allowed? Also, what is the difference between an arg with &&
and without `&&?
#include <iostream>
std::unique_ptr<int> make_obj(int v) {
return std::make_unique<int>(v);
}
void print(std::unique_ptr<int> &&v) { // <- why && allows multiple moves?
std::cout << *v << std::endl;
}
int main() {
auto val = make_obj(1);
print(std::move(val)); // the first time move
int a = 0;
print(std::move(val)); // the second time move
}