Copy Constructor DIP and implementation
Nicholas Wilson
iamthewilsonator at hotmail.com
Wed Sep 12 23:17:44 UTC 2018
On Wednesday, 12 September 2018 at 22:11:20 UTC, Manu wrote:
> On Wed, 12 Sep 2018 at 04:40, Dejan Lekic via
> Digitalmars-d-announce <digitalmars-d-announce at puremagic.com>
> wrote:
>>
>> On Tuesday, 11 September 2018 at 15:22:55 UTC, rikki
>> cattermole wrote:
>> >
>> > Here is a question (that I don't think has been asked) why
>> > not
>> > @copy?
>> >
>> > @copy this(ref Foo other) { }
>> >
>> > It can be read as copy constructor, which would be excellent
>> > for helping people learn what it is doing (spec lookup).
>> >
>> > Also can we really not come up with an alternative bit of
>> > code than the tupleof to copying wholesale? E.g.
>> > super(other);
>>
>> I could not agree more. @implicit can mean many things, while
>> @copy is much more specific... For what is worth I vote for
>> @copy ! :)
>
> @implicit may be attributed to any constructor allowing it to
> be invoked implicitly. It's the inverse of C++'s `explicit`
> keyword. As such, @implicit is overwhelmingly useful in its own
> right.
>
> This will address my single biggest usability complaint of D as
> compared to C++. @implicit is super awesome, and we must
> embrace it.
https://stackoverflow.com/a/11480555/1112970
>I have no idea why you would want to declare a copy-constructor
>as explicit
it seems that even if we were to want to have @implicit as an
opposite of C++'s explicit it would _always_ be present on
copy-constructors which means that @implicit for copy
constructors should itself be implicit.
From what I understand of explicit in C++, if we were to have
@implicit construction it would be used for things like
struct Foo
{
@implicit this(int) {}
}
void useFoo(Foo f) { ... }
void main()
{
useFoo(0); // Fine, implicitly construct auto tmp = Foo(0);
useFoo(tmp);
}
If at some point in the future we decide that we do want to add
@implicit construction, then we can make the copy constructor
always @implicit. Until that point I see no need for this,
because it is replacing postblit which is always called
implicitly.
@\all please remember to leave feedback on the actual draft
review on the DIP PR.
More information about the Digitalmars-d-announce
mailing list