From another question I see this code :
template <typename T>
std::set<T> getUnion(const std::set<T>& a, const std::set<T>& b)
{
std::set<T> result = a;
result.insert(b.begin(), b.end());
return result;
}
Can't we just use below code ? :
template <typename T>
std::set<T> getUnion(std::set<T> a, const std::set<T>& b)
{
a.insert(b.begin(), b.end());
return a;
}
Is there any difference ??
I can't understand the reason for using the first approach.
Is the second code inhibit RVO ?