Can you specify invalid iterator without container? 
Author Message
 Can you specify invalid iterator without container?

Is there a way to indicate that an iterator is uninitialized in the absense
of a container? Is there a way to initialize an iterator variable with a
"null" value? Do you need to have the container around to initialize the
iterator to container.end()?


Sun, 26 Dec 2004 22:44:40 GMT  
 Can you specify invalid iterator without container?
All iterators that are at least forward iterators must have a default
constructor, which may produce a so-called singular value of the
iterator. So you can write something like

vector<int>::iterator it; //it has singular value

The only operation allowed on iterator with a singular value is to
assign a non-singular value to it:

it = myVector.begin();

There is no way to check whether or not the iterator holds a singular or
non-singular value, and you cannot compare two iterators with singular
values ("cannot" means the behavior is undefined).

What are you really trying to do?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Is there a way to indicate that an iterator is uninitialized in the
absense
> of a container? Is there a way to initialize an iterator variable with
a
> "null" value? Do you need to have the container around to initialize
the
> iterator to container.end()?



Sun, 26 Dec 2004 23:48:08 GMT  
 Can you specify invalid iterator without container?
I have a class that has iterators some data plus an iterator into a map. The
class itself is used as the data type of another map. So:

class X
{
public:
    int    m_iUsefulData
    map<int, int>::iterator m_AnotherMapItr;
    void Dump()
    {
        printf("%u  %u\n"
            , m_iUsefulData,
            , m_AnotherMapItr->second);
            //This line Crashes if m_AntoherMapItr
            //not initialized yet
    }

Quote:
};

When an X is created I don't have a value for m_AnotherMapItr yet. I'd like
to be able to ask m_AnotherMapItr if it was initialized.


Quote:
> All iterators that are at least forward iterators must have a default
> constructor, which may produce a so-called singular value of the
> iterator. So you can write something like

> vector<int>::iterator it; //it has singular value

> The only operation allowed on iterator with a singular value is to
> assign a non-singular value to it:

> it = myVector.begin();

> There is no way to check whether or not the iterator holds a singular or
> non-singular value, and you cannot compare two iterators with singular
> values ("cannot" means the behavior is undefined).

> What are you really trying to do?
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Is there a way to indicate that an iterator is uninitialized in the
> absense
> > of a container? Is there a way to initialize an iterator variable with
> a
> > "null" value? Do you need to have the container around to initialize
> the
> > iterator to container.end()?



Mon, 27 Dec 2004 09:20:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Iterators / Valid vs. Invalid

2. VC5 Bug: Iterator requirements stricter than specified by standard

3. Iterators - Detecting Invalid vs Valid

4. iterators and containers

5. associative containers and mutable iterators

6. 'set' container iterator question

7. STL collections/containers and iterators and DLL's

8. "Invalid Address specified to RtlFreeHeap(..)"

9. Invalid Address specified to RtlValidateHeap in EXE Server

10. Invalid Address specified to RtlFreeHeap (Debug in Win2000 Proffesional+SP3)

11. Invalid Address specified to RtlValidateHeap

12. HEAP[my.exe]: Invalid Address specified to RtlValidateHeap( 1940000, 1b73290 )

 

 
Powered by phpBB® Forum Software