开发者

Returning an iterator to an element in STL Container

开发者 https://www.devze.com 2022-12-19 16:31 出处:网络
how would you check if the iterator that was returned by the function points to something in container cl开发者_开发技巧ass?Iterators are passed around as [begin,end) pairs, with the end value signify

how would you check if the iterator that was returned by the function points to something in container cl开发者_开发技巧ass?


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消