Topic: Q: What does find_first_of() do?
Author: std@maryville.com (Sam Denton)
Date: 1995/11/19 Raw View
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. ]
Author: std@maryville.com (Sam Denton)
Date: 1995/11/12 Raw View
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. ]
Author: Marian Hellema <marian@atcmp.nl>
Date: 1995/11/13 Raw View
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. ]
Author: Marian Hellema <marian@atcmp.nl>
Date: 1995/11/06 Raw View
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. ]