My answer assumes that when you say "subset", you are really searching more for the equivalent of a "substring"; that is, maintaining order of elements during the search.
Ultimately, I can't see how you could do this in anything less than O(n*m)
. Given that, you can just roll your own pretty simply:
template <typename T1, typename T2>
bool contains(std::vector<T1> const& a, std::vector<T2> const& b) {
for (typename std::vector<T1>::const_iterator i = a.begin(), y = a.end(); i != y; ++i) {
bool match = true;
typename std::vector<T1>::const_iterator ii = i;
for (typename std::vector<T2>::const_iterator j = b.begin(), z = b.end(); j != z; ++j) {
if (ii == a.end() || *j != *ii) {
match = false;
break;
}
ii++;
}
if (match)
return true;
}
return false;
}
Live demo.
(You could probably be more creative with the template parameters.)
std::set
in the first place, possibly. Are you sure thatstd::vector
is what you want? – Salotstd::includes
, about which you are correct: it assumes sorted input). – Salot