Because std::find(b, e, k) requires that *b == k be a valid comparison. It's implemented basically like this:
1 2 3 4 5 6 7
template <typename It, typename S>
It std::find(It begin, It end, const S &term){
for (; begin != end; ++begin)
if (*begin == term)
return begin;
return end;
}
Do this instead, which would be much faster than std::find() anyway:
First of all, do not do this! The code I'm about to write takes O(n log n) time. It's even worse than linear search in an unordered array! std::map::find() can find (or not) the element in O(log n) time.
what's the difference between std::find(b,e,k) and doing it like this auto p = dow_price.find("test");
Are they completely different functions? I just noticed that <vector> does not have a find() member function, and that you'll have to use std::find(b,e,k)
Yes, they're completely different. std::find() is implemented basically as in the code I wrote in my first post in this thread. std::map::find() uses the std::map's internal data structure (usually some kind of binary search tree) to quickly find the element.
std::vector doesn't have a find() function because std::vector is not designed as a search data structure. If you need to find things quickly (std::find() is not quick) you would not put them in an std::vector.