3 ms·
> returning vector<string> is an unaffordable convenience. Not anymore since C++11. Reusing vector storage is good, but you can still use move on parameter an
by ezoe 8y ago
> returning vector<string> is an unaffordable convenience.
Not anymore since C++11.
Reusing vector storage is good, but you can still use move on parameter and not the reference.
Although, in this case, reference is probably easier to write.
- milemi 8y agoI think he was concerned about the cost of allocating separate strings that go into the vector.
- romka2 8y agoYep, every string is potentially an allocation (unless it's short and std::string implements Small String Optimization) plus O(log N) allocations by the vector itself. C++11 didn't make returning the vector in this function faster because it's written in a way to take advantage of RVO. It did make growing the vector faster though -- individual strings now get moved instead of copied.