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;
}
enqueueno push_back, it inserts based on some user logic. I cannot use std::setand overload operator <, because my insertion logic is not transitive - it ( a < b && b < c)does not mean a < c.
This works, but I'm not sure its behavior is undefined. Is it safe to assign 0 to an iterator and check for 0?
source
share