Hello
I have 2 vectors which I want to compare if they contain the same element(s) (not all elements, just some specific). They hold 'some class' objects.
What would be the best way to compare those vector elements?
I've been thinking about reloading operator== in the class they contain, and the iterate through both vectors, something like:
Is there any better/faster way of doing this?Code:std::vector<some>::iterator it = v1.begin(), it2; for (; it != v1.end(); ++it) { for (it2 = v2.begin(); it2 != v2.end(); ++it2) { if (*it == *it2) std::cout << "vectors contain the same element\n"; } }
Maybe some other container would be more suitable? Please note that I need random access iterator.
Many thanks in advance!