Velocity Reviews > C++ > STL - an algorithm for finding a collection within a collection?

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

Dylan
Guest
Posts: n/a

 03-21-2005
Is there an STL algorithm that will return true if each element in
coll1 is present in coll2

Jerry Coffin
Guest
Posts: n/a

 03-21-2005
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.

Ioannis Vranos
Guest
Posts: n/a

 03-21-2005
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

Paul Dubuc
Guest
Posts: n/a

 03-21-2005
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

kwijibo28
Guest
Posts: n/a

 03-21-2005
Dylan <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> 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

Daniel T.
Guest
Posts: n/a

 03-22-2005
In article <(E-Mail Removed)>,
Dylan <(E-Mail Removed)> 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.