Reputation: 383
function begin in vector http://www.cplusplus.com/reference/vector/vector/begin/ returns a random access iterator, while function find takes InputIterator http://www.cplusplus.com/reference/algorithm/find/, as the example shows "it = find (myvector.begin(), myvector.end(), 30);". Do the random access iterator get converted to InputIterator to be used with find?
Upvotes: 0
Views: 311
Reputation: 50053
There is no conversion needed because every random access iterator already is an input iterator.
Random access iterator and input iterator are not types, but concepts. Since the requirements for random access iterator are more strict than those for input iterator, my first sentence holds.
Maybe the same thing in more beginner friendly terms: If you want to pass a "Vehicles only" sign with your car, you do not need to do anything special because your car already is a vehicle. Same with the iterator concepts.
Bottom of the line: You can just pass the return value of std::vector::begin
to std::find
, there are no problems or pitfalls what so ever.
Upvotes: 6