Just asking, is this still undefined behavior?
vecExplode
is actually still returning a std::vector<std::string>
value, but loading it as a reference seems wrong, just asking if (even though useless) it can still be undefined..?
std::vector<std::string> vecExplode(const std::string& str, const char ch, const bool allowEmpty)
{
std::string next;
next.reserve(1024);
std::vector<std::string> result;
result.reserve(16);
// Check if it even exists. If not, return result instantly
for (auto it = str.begin(); it != str.end(); ++it)
{
const char pStr = *it;
if (pStr == ch)
{
if (!next.empty() || allowEmpty)
{
result.push_back(next);
next = "";
}
}
else
{
next += pStr;
}
}
if (!next.empty())
result.push_back(next);
return result;
}
void func()
{
const std::vector<std::string>& args = vecExplode(someString, ' ');
}
This is just a question.