Skip to main content
Code Review

Return to Revisions

6 of 6
replaced http://stackoverflow.com/ with https://stackoverflow.com/

boost::unordered_set intersection using templates

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that it was overkill. I would like the method to take in 2 sets and return a set.

class SetUtilites{
public:
 template<typename Type>
 static boost::unordered_set<Type> intersection(const boost::unordered_set<Type> &set1, const boost::unordered_set<Type> &set2){
 if(set1.size() < set2.size()){
 boost::unordered_set<Type> iSet;
 boost::unordered_set<Type>::iterator it;
 for(it = set1.begin(); it != set1.end();++it){
 if(set2.find(*it) != set2.end()){
 iSet.insert(*it);
 }
 }
 return iSet;
 }else{
 return intersection(set2,set1);
 }
 }
};
pbible
  • 419
  • 1
  • 7
  • 17
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /