954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

elements common to more than one vector

Is there a function that I can use that given a few vectors which elements are common to all?

for example
vector a;
vector b;

a.push_back( 1 );
a.push_back( 2 );
a.push_back( 3 );
a.push_back( 4 );

b.push_back( 2 );
b.push_back( 4 );

Something that will give me back the answer of 2 and 4? (The results would be stored in another vector).

What if I have more than 2 vectors to compare - would I somehow call this function against each pair? (ie a vs. b, b vs. c, a vs. c?)

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

boost may have one. search that link for the word intersect and see how it is used.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

>Is there a function that I can use that given a few vectors which elements are common to all?
Look up set_intersection.

>What if I have more than 2 vectors to compare
Look up set_intersection with a focus on the return value and consider making multiple calls.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You