T
techie
I want to find an element in a sequence or map by comparing its value
(not the key). I can search for an element with a particular value in
a sequence or map by iterating through the elements one by one using
an iterator for the container. I could alternatively use the the
std::find or std::find_if algorithms to find an element in a sequence
or map respectively. For example, to find an element in a map I could
write a function object to check the value of an element:
http://www.josuttis.com/libbook/cont/mapfind.cpp.html
I guess internally the std::find or std::find_if internally use
iterators to search for an element. Is there any advantage of using
the algorithms over for loops that use iterators. What is the best
most efficient method? Using algorithms or using iterators?
(not the key). I can search for an element with a particular value in
a sequence or map by iterating through the elements one by one using
an iterator for the container. I could alternatively use the the
std::find or std::find_if algorithms to find an element in a sequence
or map respectively. For example, to find an element in a map I could
write a function object to check the value of an element:
http://www.josuttis.com/libbook/cont/mapfind.cpp.html
I guess internally the std::find or std::find_if internally use
iterators to search for an element. Is there any advantage of using
the algorithms over for loops that use iterators. What is the best
most efficient method? Using algorithms or using iterators?