using namespace std;
class myList
{
public:
mylist():_internalList(),_lastPostition(0)
{
}
typedef list<string>::iterator Itr;
bool enqueue(string);
Itr next()
{
if(_lastPostition == 0)
_lastPostition = _internalList.begin();
if(_lastPostition == _internalList.end())
return (_lastPostition = 0);
return _lastPostition++;
}
private:
list<string> _internalList;
Itr _lastPostition;
}
enqueue
不是 push_back
,它根据一些自定义逻辑插入。
我不能使用 std::set
和重载operator <
,因为我的插入逻辑不是可传递的 - ( a < b && b < c)
并不意味着 a < c
.
这有效,但我不确定它是否是未定义的行为。 将 0 分配给迭代器并检查 0 是否安全?
最佳答案
“将 0 分配给迭代器并检查 0 是否安全?”没有。
关于c++ - 空迭代器会导致未定义的行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5374979/