Re: strange crash after assertion with std::map::iterator



At the end of this sequence, 'i' is invalid. Would you expect to be able
to test for it? If so, how would you go about it, if you were writing the
C++ standard? How would you go about it if you were STL implementor?

I never said that ANY invalid iterator has to be usable, only that a
value-initialized iterator should be at least equality/inequality
comparable with any other iterator of the same type. the implementation,
I'd bet, would be trivial, since iterators are pointers or they contain
pointers, and pointers may be set to null.

That opens another can of worms.

1. What additional properties (if any), should the standard have for any
iterator where such pointer is null?
2. If I have 2 such iterators, what if I do

sort(it1, it2);

3. end() for a container is not derefenceable and sometimes plays the role
of an "invalid iterator".
Now what happens if I compare a null iterator with end()? - Are they equal?
Less than (for vector and deque)?

Thanks

Stephen Howe


.



Relevant Pages

  • Re: abstract containers: does such a thing exist, conceptually?
    ... create a firewall between different types of lists. ... > behaviour by the additional pointers. ... I do not like much STL's style of iteration with iterator objects, ... For example, an array view for containers with ordered elements, ...
    (comp.object)
  • Re: strange crash after assertion with std::map::iterator
    ... value-initialized iterator should be at least equality/inequality ... I'd bet, would be trivial, since iterators are pointers or they contain ... What additional properties, should the standard have for any ... Now what happens if I compare a null iterator with end? ...
    (microsoft.public.vc.stl)
  • Re: Pointer To A Vector Elements While Still Adding
    ... however there are cases that pointers get invalidated too in deque case. ... "surface" encapsulation about the type of the target container used, ... "surface" encapsulation can be provided by a typedef of the iterator type used. ...
    (comp.lang.cpp)
  • Re: Vector.Erase?
    ... So I tried to change it using iterator, but the result does not acting ... only on iterators, not pointers. ... vector::iterator was a pointer in the VC6 STL. ... gratuitously embed expressions with side-effects inside other expressions): ...
    (microsoft.public.vc.mfc)
  • Re: strange crash after assertion with std::map::iterator
    ... involving pointers, exhibit undefined behavior. ... assert with iterator debugging disabled? ...
    (microsoft.public.vc.stl)

Loading