Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why there is no find for vector in C++

Tags:

c++

stl

stdvector

what's the alternative?

Should I write by myself?

like image 202
skydoor Avatar asked Jun 08 '10 00:06

skydoor


1 Answers

The reason there is no vector::find is because there is no algorithmic advantage over std::find (std::find is O(N) and in general, you can't do better for vectors).

But the reason you have map::find is because it can be more efficient (map::find is O(log N) so you would always want to use that over std::find for maps).

like image 50
R Samuel Klatchko Avatar answered Sep 20 '22 05:09

R Samuel Klatchko