Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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
 
Reply With Quote
 
 
 
 
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.

 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
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
 
Reply With Quote
 
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
 
Reply With Quote
 
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STL algorithm for finding first non-matching value Stephen Howe C++ 5 07-20-2011 08:15 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Filtered Back Projection Algorithm (FBP Algorithm) Bapaiah Katepalli VHDL 1 06-23-2006 04:50 PM
ASP JavaScript: Garbage collection algorithm Benjamin Johnston ASP General 2 12-02-2005 11:24 AM
Key generation algorithm and Cipher algorithm Ahmed Moustafa Java 0 11-15-2003 06:35 AM



Advertisments