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

Discussion in 'C++' started by Dylan, Mar 21, 2005.

  1. Dylan

    Dylan Guest

    Is there an STL algorithm that will return true if each element in
    coll1 is present in coll2
    Dylan, Mar 21, 2005
    #1
    1. Advertising

  2. Dylan

    Jerry Coffin Guest

    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.
    Jerry Coffin, Mar 21, 2005
    #2
    1. Advertising

  3. 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
    Ioannis Vranos, Mar 21, 2005
    #3
  4. Dylan

    Paul Dubuc Guest

    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
    Paul Dubuc, Mar 21, 2005
    #4
  5. Dylan

    kwijibo28 Guest

    kwijibo28, Mar 21, 2005
    #5
  6. Dylan

    Daniel T. Guest

    In article <>,
    Dylan <> 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.
    Daniel T., Mar 22, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    0
    Views:
    763
    Ahmed Moustafa
    Nov 15, 2003
  2. qazmlp

    Finding out the GC algorithm

    qazmlp, Feb 27, 2004, in forum: Java
    Replies:
    4
    Views:
    1,712
    Tim Tyler
    Feb 29, 2004
  3. Bapaiah Katepalli
    Replies:
    1
    Views:
    1,481
    Mike Treseler
    Jun 23, 2006
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    946
    Øyvind Isaksen
    May 18, 2007
  5. Stephen Howe
    Replies:
    5
    Views:
    464
    James Kanze
    Jul 20, 2011
Loading...

Share This Page