[英]Returning an iterator to an element in STL Container
您如何检查该函数返回的迭代器是否指向容器类中的某个东西?
Iterators are passed around as [begin,end) pairs, with the end value signifying "not found" or other forms of the empty sequence. 迭代器以[begin,end)对的形式传递,其终止值表示“未找到”或其他形式的空序列。 Return that from your function, or return a
pair<bool,iterator>
(or similar). 从函数中返回该值,或返回一个
pair<bool,iterator>
(或类似值)。
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.
但这将是可怕的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.