🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Marian Hellema Mon, 06 Nov 1995 10:50
Q: What does find_first_of() do?
#2437
Author: Marian Hellema
Date: Mon, 06 Nov 1995 10:50
37 lines
2136 bytes
I am not sure what the algorithm find_first_of() does.
At first glance I thought it finds the first occurence of an element
of a sequence.
So if I have:

int v1[10] = { 0,1,2,3,3,5,3,7,8,8 };
int v2[3] = {3,6,2 };
int *p = find_first_of( v1, v1+10, v2, v2+3 );

it would return an iterator to the first 3.
But then I read section 25.1.4 in the april working paper:

      find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
                    ForwardIterator2 first2, ForwardIterator2 last2);

    Returns:
    The first iterator i in  the  range  [first1,  last1-(last2-first2))
    such  that for any non-negative integer n < (last2-first2), the fol-
    lowing   corresponding   conditions   hold:   *i   ==   *(first2+=n),
    pred(*i,*(first2+n))  == true.  Returns last1 if no such iterator is
    found.

I simply do not understand what this says; the more I read it, the more
I get confused. It seems to say that all the elements in the second range
[first2, last2) should have the same value??

Thanks to anyone who can explain,
Marian
--
----------------------------------------------------------------------
Marian Hellema            AT Computing, UNIX training and consultancy
email: marian@atcmp.nl    P.O. Box 1428, 6501 BK Nijmegen
phone: +31 24 3527225     the Netherlands
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Q: What does find_first_of() do?
#2495
Author: Dick Menninger
Date: Fri, 10 Nov 1995 19:40
50 lines
2435 bytes
If you compare it with find_end which precedes it,
this appears to be a typo and should read:

> ==========Marian Hellema, 11/6/95==========
> 
> I am not sure what the algorithm find_first_of() does.
> At first glance I thought it finds the first occurence of an element
> of a sequence.
> So if I have:
> 
> int v1[10] = { 0,1,2,3,3,5,3,7,8,8 };
> int v2[3] = {3,6,2 };
> int *p = find_first_of( v1, v1+10, v2, v2+3 );
> 
> it would return an iterator to the first 3.
> But then I read section 25.1.4 in the april working paper:
> 
>       find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
>                     ForwardIterator2 first2, ForwardIterator2 last2,
                                                BinaryPredicate pred);
                                                (^you left this off^)

> 
>     Returns:
>     The first iterator i in  the  range  [first1, 
last1-(last2-first2))
>     such  that for any non-negative integer n <
(last2-first2), the fol-
>     lowing   corresponding   conditions   hold:   *i   ==  
*(first2+=n),
                                                 *(i+n)  ==  
*(first2+=n)
                                                  ^^^^^
>     pred(*i,*(first2+n))  == true.  Returns last1 if no such
iterator is
  pred(*(i+n),*(first2+n))  == true
        ^^^^^
>     found.
> 

In your case, it should return v1+10 since {3,6,2} is not a
subsequence of v1.

Good Day
Dick
Dick.Menninger@DaytonOH.ATTGIS.COM
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Q: What does find_first_of() do?
#2540
Author: Marian Hellema
Date: Mon, 13 Nov 1995 16:12
63 lines
3315 bytes
Dick Menninger <Dick.Menninger@daytonoh.attgis.com> wrote:
>If you compare it with find_end which precedes it,
>this appears to be a typo and should read:
>
>> ==========Marian Hellema, 11/6/95==========
>> 
>> I am not sure what the algorithm find_first_of() does.
>> At first glance I thought it finds the first occurence of an element
>> of a sequence.
>> So if I have:
>> 
>> int v1[10] = { 0,1,2,3,3,5,3,7,8,8 };
>> int v2[3] = {3,6,2 };
>> int *p = find_first_of( v1, v1+10, v2, v2+3 );
>> 
>> it would return an iterator to the first 3.
>> But then I read section 25.1.4 in the april working paper:
>> 
>>       find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
>>                     ForwardIterator2 first2, ForwardIterator2 last2,
>                                                BinaryPredicate pred);
>                                                (^you left this off^)
>
>> 
>>     Returns:
>>     The first iterator i in  the  range  [first1, last1-(last2-first2))
>>     such  that for any non-negative integer n <(last2-first2), the fol-
>>     lowing   corresponding   conditions   hold:   *i   ==  *(first2+=n),
>                                                 *(i+n)  ==  *(first2+=n)
>                                                  ^^^^^
>>     pred(*i,*(first2+n))  == true.  Returns last1 if no such iterator is
>  pred(*(i+n),*(first2+n))  == true
>        ^^^^^
>>     found.
>> 
>
>In your case, it should return v1+10 since {3,6,2} is not a
>subsequence of v1.

Thanks for your reply. Several people have suggested this "typo" in the
draft, but I don't think your interpretation is correct. What you describe as
the behavior of find_first_of()  fits exactly the description of search(),
see 25.1.9 of the standard working paper.

My suspicion, which was confirmed by Samuel Danton, is that the "typo" is
in the phrase "... for any non-negative integer n...". I think this is meant
to be:
".. for some non-negative integer n...".
This interpretation is conform the memberfunction find_first_of() of class
string,
see 21.1.1.9.3 of the working paper.

Regards,
Marian
-- 
----------------------------------------------------------------------
Marian Hellema            AT Computing, UNIX training and consultancy
email: marian@atcmp.nl    P.O. Box 1428, 6501 BK Nijmegen
phone: +31 24 3527225     the Netherlands
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Q: What does find_first_of() do?
#2661
Author: Sam Denton
Date: Sun, 19 Nov 1995 19:20
33 lines
1711 bytes

Marian Hellema <marian@atcmp.nl> revealed:
|I am not sure what the algorithm find_first_of() does.
|      find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
|                    ForwardIterator2 first2, ForwardIterator2 last2);

|    Returns:
|    The first iterator i in  the  range  [first1,  last1-(last2-first2))
|    such  that for any non-negative integer n < (last2-first2), the fol-
|    lowing   corresponding   conditions   hold:   *i   ==   *(first2+=n),
|    pred(*i,*(first2+n))  == true.  Returns last1 if no such iterator is
|    found.

|I simply do not understand what this says; the more I read it, the more
|I get confused. It seems to say that all the elements in the second range
|[first2, last2) should have the same value??

I think that instead of saying "for any", they mean to/should say
"there exists a"  I agree that it is confusing.
--
Samuel T. Denton, III  (std@maryville.com)

Any similarily between opinions expressed herein and those of 
my employer is purely coincidental.

Hail Eris!  All Hail Discordia!


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads