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 is not push_back, it inserts based on some custom logic.
I can’t use std::set and overload operator <, because my insertion logic isn’t transitive – ( a < b && b < c) does not imply a < c.
This works but I’m not sure if its an undefined behavior.
Is it safe to assign 0 to an iterator and check for 0 ?
“Is it safe to assign 0 to an iterator and check for 0 ?” No.