I am trying to create a data structure called Disjoint Set. Looking at theory what i thought of is something like this :
std::vector<std::pair<int,std::set<int>>> DisjointSet;
for(auto i=0;i<10;++i) DisjointSet.push_back( std::make_pair(i,std::set<int>().insert(i)));
but this code gives which is beyond my understanding , so this is good design to make Disjoint Set. Also how do i get rid of these errors?
set::insertdoesn’t return the set itself. You need to create the set beforehand,insertand then use it inmake_pair. This does the trick with nearly no overhead for the copy usingmove: