Is there any way to do std::set_intersection on two different types of sets?
I have two sets:
std::set<X1> l_set1;
std::set<X2> l_set2;
I'm able to define some comparator for them that checks if X1 and X2 are equal.
struct sample_comparer
{
bool operator()(const &X1 p_left, const &X2 p_right)
{
return p_left == p_right;
}
};
Now, I try to do a set intersection on those two sets:
std::set<X1> l_intersect;
std::set_intersection(l_set1.begin(), l_set1.end(), l_set2.begin(), l_set2.end(),
std::inserter(l_intersect, l_intersect.begin()), sample_comparer());
Unfortunately, I can't force this code to work. I'm not even sure if this is possible, but from the description of set_intersection I know that I can use two different iterators.
I tried to search for some code samples that do what I want, but didn't found any? Could someone present me a working code sample for my problem?
Update: the error is:
error: stl_function.h:227: no match for 'operator<' in '__x < __y'
Thanks in advance!
bool operator<(X1,X2)
– Saltandpepper