Please consider this code, I have seen this type of code several times,
std::vector<std::string> read_file(const std::string& path)
std::cerr << "Unable to open file" << "\n";
std::vector<string> words;//this vector will be returned
while (std::getline(file, token, ','))
Can we guarantee it will not die?
As long there is no reference returned, it's perfectly fine to do so.
words will be moved to the variable receiving the result.
The local variable will go out of scope. after it was moved (or copied).