Deprecating this(this)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Apr 4 22:54:17 UTC 2018


On Wednesday, April 04, 2018 22:41:39 Stefan Koch via Digitalmars-d wrote:
> On Wednesday, 4 April 2018 at 22:30:39 UTC, Walter Bright wrote:
> > On 4/1/2018 3:49 AM, bachmeier wrote:
> >> What I was wondering too. I mean, breaking changes just don't
> >> happen to this language. Now there will be, without even an
> >> indication of how existing code would have to be rewritten, or
> >> how this large-scale breakage is different than the breakages
> >> that just can't happen because reasons. I guess that's why
> >> there's always the disclaimer, "We'll only break code if
> >> there's a really good reason." That reason is "in case we want
> >> to".
> >
> > The idea is not to introduce a breaking change. Postblits will
> > remain. The copy constructor will be an additional construct,
> > and if one is defined, it will be preferred.
> >
> > Eventually (years later) postblits will be slowly deprecated
> > and eventually removed.
>
> Could you describe how a copy constructor differs from postblit ?

With a postblit, all of the members are copied _before_ the postblit
constructor is called, meaning that the struct was blitted, and then the
postblit constructors were called for each member variable that has a
postblit constructor, before the struct's postblit constructor is called.
So, inside the postblit constructor, you're mutating an already copied
object. It's doing work post the copy - hence postblit.

With a copy constructor, the copy is being directly constructed. Each member
will be initialized exactly once rather than being initialized and then
mutated. Ideally, each member that was not explicitly initialized by the
copy constructor would be automatically copied from the original so that you
wouldn't have to explicitly copy each member, so syntactically, it may look
very much like a postblit constructor, but the key difference is that with a
copy constructor, the copy is directly constructed with whatever changes are
done by the copy constructor as opposed to having it copied and then
mutated.

- Jonathan M Davis



More information about the Digitalmars-d mailing list