Re: looking for std::list::iterator NULL value

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Ben Voigt wrote:
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:OxnZ3g2MHHA.780@xxxxxxxxxxxxxxxxxxxxxxx
Ben Voigt <rbv@xxxxxxxxxxxxx> wrote:
I need an iterator value representing "not set" or "unassigned".
With a pointer into an array or linked list, I would just use the
value NULL. Is this possible with the standard library iterators?

A common choice for a special value iterator is container.end()

Can container.end() ever become a viable iterator, for example if
more items are added to a vector? Am I safe with a list?

You're fine. No list iterators are changed by insertions (and 'end'
is not changed by removals), so you can retain the value. However,
with other containers you're better off calling 'end' member every
time.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


.



Relevant Pages

  • Re: Sorting records using sort()
    ... We have an array of n*m bytes. ... >> The trouble with writing iterators for this problem is that he needs it ... We create a proxy class and let the iterator return proxy objects. ... that is used only inside the iterator, it sets the data pointer to point ...
    (comp.lang.cpp)
  • Re: [C++] Vector - guaranteed to be contiguous?
    ... Is this possible if an iterator is not a pointer?" ... you can use pointers as iterators into that data. ... Mostly that means you can use pointers to items in an array as random ... access iterators into that array. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: vector acces by index/iterator
    ... > It's not a misconception I've noticed. ... >> Vectors use random iterators. ... > Arrays have random-access iterators. ... A pointer into an array does ...
    (comp.lang.cpp)
  • Re: [PHP] RecursiveArrayIterator
    ... Isn't that what garbage collection is for? ... is saying is Iterators dont bother creating a copy of the array, ... > dangling in memory. ... SPL iterators do things differently and know only one ...
    (php.general)
  • Re: Heres a Python-like range() for JavaScript. Is it new?
    ... I think it easier to slice an array than to code a function. ... Allocating memory for an array object of arbitrary length and then keeping that array in memory just to use its `length` is silly, ... similar concerns were the reasons iterators were implemented in newer versions of JavaScript. ... Yes, `this` references global object, since `call` was invoked with first argument being `undefined`. ...
    (comp.lang.javascript)