In case you want a more formal statement of what's supported, here's what the standard has to say. About the best searching we can do is with a binary search, such as std::lower_bound
(§25.4.3.1/3):
Complexity: At most log2(last − first
) + O(1) comparisons.
That only tells us the number of comparisons though. To move through the container, lower_bound
uses std::advance
. About an std::list we find (§23.3.5.1/1):
A list is a sequence container that supports bidirectional iterators [...]
So, how does std::advance
work for a collection that provides bidirectional iterators?
(§24.4.4/1):
[...] for input, forward and bidirectional iterators they use ++ to provide linear time implementations.
So, to find anything in a list (by either value or position) we're going to be looking at linear complexity overall, with a logarithmic number of comparisons. To be honest, we're probably better off with std::find
(§25.2.5/2):
Complexity: At most last - first
applications of the corresponding predicate.
The choice between the two may not always be entirely obvious though -- traversing the list is obviously linear. std::find
minimizes traversal, while std::lower_bound
minimizes comparisons. If comparison is a lot more expensive than traversal, std::lower_bound
will probably do better. If comparison is fairly cheap, std::find
is probably better.