Re: strange crash after assertion with std::map::iterator
consider the difference between
struct foo
{
int i_;
foo() {}
};
and
struct foo
{
int i_;
foo() : i_(0) {}
};
Well that's sort of what I'm talking about. Both
are valid.
However, the STL was designed for performance but making a
default-constructed iterator equal to the end iterator imposes a
significant overhead. Therefore it simply is not done.
I strongly disagree.
An iterator is a small structure, and initializing some pointers to 0 is
surely overhead, but definitely not significant -- it's O(1).
I sort of agree with you but not exactly <g> For one thing, there
is no reason to assume that pointers are involved here at all.
Secondly, I have a problem understanding how this would
work. I mean, setting a pointer to 0 is understandable but
setting an iterator to end is less clear to me. End of what?
end() is a member of a container. What it returns is irrelevant
in that you can never compare to it. You always compare
to end(). So given:
std::vector<int> i;
std::vector<int> j;
std::vector<int>::iterator it;
You want the following to test true:
if(it == i.end()) //
if(it == j.end()) //
That's where you sort of lose me. I don't think that
you can define this behavior based on the idea that
iterators are likely built with pointers to begin with.
And I don't think that ::end() returns 0.
Now if you want to argue that std::string foo(0) should
construct an empty string ...