Is it dangerous to return a reference wrapper like showed below:
std::vector<std::reference_wrapper<int>> foo() {
int x = 10;
std::vector<std::reference_wrapper<int>> vec;
vec.push_back(x);
return vec;
}
foo2() {
std::cout << foo()[0] << std::endl;
}
I assume the local/stack variable x can be lost in foo2()
.