Re: strange crash after assertion with std::map::iterator
Mycroft Holmes wrote:
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:pqds2353m8f1kigln649l1i0tes61mecnb@4ax.com...
On Tue, 24 Apr 2007 12:30:53 -0400, "Duane Hebert" <spoo@flarn.com> wrote:
At any rate, my point was that I don't think the standard guarantees
in general that foo f is equivalent to foo f = foo().
It doesn't.
the standard doesn't, but iterators have VALUE semantics (as, say, strings),
so this should be granted.
for more generic objects this is not granted, however such an object would
be at least misleading and at most wrong.
I would imagine that for a typical iterator class,
typedef std::map<int, int>::iterator it;
it i; //1 default-initialized
it i = it(); //2 value-initialized temporary then copy-initialized
it i((it())); //3 value-initialized temporary then direct-initialized
It is possible for a map iterator to be a POD type (e.g. no
user-declared constructors), in which case 1 will leave any pointers in
the iterator uninitialized, while 2 and 3 will 0 initialize them. In the
more likely case that map iterator does have a constructor, then there
must also be a user-declared default constructor, so 1, 2 and 3 will all
behave identically.
Tom