Copy Constructor DIP

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jul 12 14:54:53 UTC 2018


On Thursday, 12 July 2018 07:45:30 MDT Andrei Alexandrescu via Digitalmars-d 
wrote:
> > I also very much dislike the syntax - it makes no sense to me at all. I
> > commented on the PR itself asking why it differs so much from C++ -
> > specifically, what's bad about the C++ way of doing things there that we
> > want to avoid?
>
> C++ is at the other end of the spectrum - constructors are too implicit,
> so the "explicit" keyword has been introduced with the advice to use it
> in the vast majority of cases. If C++ could do it again, it would make
> everything explicit and add an "implicit" keyword.

That's only an issue in C++, because C++ uses constructors for implicit
conversions unless you mark them with explicit. D doesn't ever do implicit
conversions like that. All constructors are effectively explicit. Is this
DIP proposing that we add such implicit conversions? Because if it is,
that's a pretty major change that arguably has nothing to do with copy
constructors, since copy constructors are for constructing an object from
another object of the same type (though possibly of different mutability),
not from objects of other types. That would just be a normal constructor.

I really don't understand what the purpose of @implicit is here. What's the
problem of just going off of the type of the constructor's single parameter
to determine whether it's a copy constructor?

- Jonathan M Davis





More information about the Digitalmars-d mailing list