In this case is it worthwhile to consider that the method "merge" should return a reference on a set instead of a copy of a set. In the case of I want to return a reference on a set how should I handle the case ?
#include <iostream>
#include <set>
using namespace std;
class T {
public:
set<int> merge();
private:
set<int> a = {1, 2, 3};
set<int> b = {4, 5, 6};
};
set<int>
T::merge()
{
set<int> merged;
merged.insert(a.begin(), a.end());
merged.insert(b.begin(), b.end());
return merged;
}
int main(int argc, const char * argv[]) {
T test;
auto r = test.merge();
for(auto e: r)
cout << e << endl;
return 0;
}