Reputation: 1047
Could anyone tell me the simplest way to check if a vector A, includes an element of vector B?
it would be sort of:
for every element in A (
if (none of the elements in B exist in A) do something and B changes
else (do nothing) )
I guess it could be done by with some loops. But is there a function that would make it easier?
Upvotes: 1
Views: 380
Reputation: 1519
The STL includes
function is designed for exactly this.
http://www.cplusplus.com/reference/algorithm/includes/
Upvotes: 2
Reputation: 217275
You std::sort
them, then use std::set_intersection
(or similar algorithm) to have included elements.
Upvotes: 0