468,780 Members | 2,259 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

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

Is there an STL algorithm that will return true if each element in
coll1 is present in coll2
Jul 23 '05 #1
5 1016
Dylan wrote:
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).

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 23 '05 #2
Dylan wrote:
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.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #3
Dylan wrote:
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.

--
Paul M. Dubuc
Jul 23 '05 #4
Dylan <sp******@ontheball.com> wrote in message news:<gp********************************@4ax.com>. ..
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2


Look at:
http://www.sgi.com/tech/stl/includes.html

kwijibo
Jul 23 '05 #5
In article <gp********************************@4ax.com>,
Dylan <sp******@ontheball.com> wrote:
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.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by m sergei | last post: by
32 posts views Thread by someone else | last post: by
2 posts views Thread by The One We Call 'Dave' | last post: by
2 posts views Thread by premgrps | last post: by
prometheuzz
4 posts views Thread by prometheuzz | last post: by
reply views Thread by Chris M. Thomasson | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.