如何检查迭代器是否在没有容器的情况下结束? [英] How to check whether the iterator hit the end without container?

查看:53
本文介绍了如何检查迭代器是否在没有容器的情况下结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如何在没有任何其他信息的情况下实现以下功能?

For example, how to implement the following function without any other information?

bool isEnd(set<int> :: iterator itr);

我知道我可以这样做,但是如何在没有输入变量"s"的情况下做到这一点?

I know I can do it like this, but how to do it without input variable "s"?

bool isEnd(const set<int> &s, set<int> :: iterator itr) {
    return itr == s.end();
}

推荐答案

使用标准C ++库,无法编写该代码.

With the standard C++ library, there is no way to write that.

std :: set 可以实现为例如红黑树,然后迭代器是其中的节点,您需要整棵树才能确定如果该节点是最后一个节点.

std::set can be implemented as e.g. red-black trees, and then iterators are nodes inside, and you need the entire tree to figure out if that node is the last.

这篇关于如何检查迭代器是否在没有容器的情况下结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆