find_first_of

P

pauldepstein

From C++ Primer:

BEGIN QUOTE

Algorithms to find one of many values. These algorithms require two
pairs of forward iterators. They search for the first (or last)
element in the first range that is equal to any element in the second
range ... There is no requirement that the types of beg1 and beg2
match exactly. However, it must be possible to compare the element
types of the two sequences. So, for example, if the first sequence is
a list<string>, then the second could be a vector<char*>.
.... find_first_of(beg1, end1, beg2, end2) Returns an iterator to the
first occurrence in the first range of any element from the second
range ...

END QUOTE

Could someone explain any rules (or rules of thumb) for determining
when elements can be compared between the ranges? For example, I
would not know that it was legal to compare vector<char*> members with
list<string> members.

Thank you very much for your help.

Regards,

Paul Epstein
 
J

Juha Nieminen

Could someone explain any rules (or rules of thumb) for determining
when elements can be compared between the ranges? For example, I
would not know that it was legal to compare vector<char*> members with
list<string> members.

std::string has an operator==() which takes a const char*, so that
std::strings can be compared to const char* strings.

The algorithm in question just calls operator== of the elements, so it
ends up calling that function.
 
J

James Kanze

std::string has an operator==() which takes a const char*, so
that std::strings can be compared to const char* strings.
The algorithm in question just calls operator== of the
elements, so it ends up calling that function.

In sum, the question isn't what find_first_of supports, but what
the value_types of the iterators support. There's also a
version of the function template with an additional argument
allowing you to specify a comparison function, so you can
literally do anything.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top