cpx
cpx

Reputation: 17557

Returning an iterator to an element in STL Container

how would you check if the iterator that was returned by the function points to something in container class?

Upvotes: 1

Views: 191

Answers (2)

Roger Pate
Roger Pate

Reputation:

Iterators are passed around as [begin,end) pairs, with the end value signifying "not found" or other forms of the empty sequence. Return that from your function, or return a pair<bool,iterator> (or similar).

Upvotes: 1

John Dibling
John Dibling

Reputation: 101446

You can't. Make sure you return a valid iterator.

Well I suppose you could by iterating through the container and checking to see if the iterators are equal. But that would be horrid.

Upvotes: 0

Related Questions