I have the following code on c++17
template<typename T>
std::vector<T*> getPointerVector(std::vector<T> base) {
auto out = std::vector<T*>();
for (auto& t : base) {
out.push_back(&t);
}
return out;
}
As far as i understand RVO should kick in and prevent any copying of the returned vector. However, when i use GCC it all works fine, using msvc it does not and the vector is actually copied. Any explanations? Thanks!
Edit: When I debugged I made sure the reference in memory is the same for the vector inside the function and on the calling side. That is true for gcc 8.3 on debian testing and not true for msvc on visual studio 19.4