Initialization of std.typecons.RefCounted objects
monarch_dodra
monarchdodra at gmail.com
Wed Jul 18 22:39:52 PDT 2012
On Wednesday, 18 July 2012 at 13:32:39 UTC,
travert at phare.normalesup.org (Christophe Travert) wrote:
> I think opIndex should return by reference. opIndexAssign is of
> no help
> when the user want to use a function that takes a reference
> (here
> Array.insert).
Having already brought this up before, the answer to that is that
the containers inside "container" are meant to be "closed" and
not give access to the addresses of their internals, so the
return by value is on purpose:
Here is Andrei's post about this:
http://forum.dlang.org/thread/ceftaiklanejfhodbpix@forum.dlang.org?page=2#post-jthdko:24231u:241:40digitalmars.com
That said, I had brought up the exact same issue here:
http://forum.dlang.org/thread/bkozswmsgeibarowfwvq@forum.dlang.org
> It is normal that Array uses default construction when
> someone increases the array's length.
> Besides that point, I don't see why default-constructed Array
> have an
> uninitialised Payload. This makes uninitialised Array behaves
> unexpectedly, because making a copy and using the copy will not
> affect
> the original, which is not the intended reference value
> behavior.
I think it would be better to "initialize on copy", rather than
default initialize. There are too many cases an empty array is
created, then initialized on the next line, or passed to
something else that does the initialization proper.
You'd get the correct behavior, and everything else (except dupe)
works fine anyways.
More information about the Digitalmars-d
mailing list