STL - an algorithm for finding a collection within a collection?

D

Dylan

Is there an STL algorithm that will return true if each element in
coll1 is present in coll2
 
J

Jerry Coffin

Dylan said:
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2

I don't know of one specifically for this, but if this was the case,
the result from set_difference would be empty (this requires both
collections to be sorted).
 
I

Ioannis Vranos

Dylan said:
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2


If you want to check if the sequences are exactly the same, use std::equal.
 
P

Paul Dubuc

Dylan said:
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2

I think this requires sorted elements. I would use the std::mismatch()
algorithm. With the pair of iterators it returns you can tell if the containers
have equal contents or if one is a subset of the other.
 
D

Daniel T.

Dylan said:
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2

template <class InputIterator1, class InputIterator2>
bool includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2);

template <class InputIterator1, class InputIterator2,
class StrictWeakOrdering>
bool includes(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
StrictWeakOrdering comp);

Includes tests whether one sorted range includes another sorted range.
That is, it returns true if and only if, for every element in [first2,
last2), an equivalent element [1] is also present in [first1, last1)
[2]. Both [first1, last1) and [first2, last2) must be sorted in
ascending order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top