May 23, 2013
And if I do this:

A a;
a = b.getA();

I get what I want. What a spasm...
May 23, 2013
On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
> I know that D has (sadly) no C++ references, but I still think that
>
> A a = some_existing_A;
>
> should call opAssign.

Now I see what has you confused. Whether postblit or opAssign is called, depend on left, not right side of assignment. Object 'a' didn't exists prior, so postblit is called, and copy ctor is called with respect of 'a' as 'this' argument.
May 23, 2013
On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
> I know that D has (sadly) no C++ references, but I still think that
>
> A a = some_existing_A;
>
> should call opAssign.

Actually, it is similar to C++ : http://codepad.org/lkPMU1Ne
May 23, 2013
On Thursday, 23 May 2013 at 12:07:40 UTC, Maxim Fomin wrote:
> On Thursday, 23 May 2013 at 11:57:04 UTC, Namespace wrote:
>> I know that D has (sadly) no C++ references, but I still think that
>>
>> A a = some_existing_A;
>>
>> should call opAssign.
>
> Now I see what has you confused. Whether postblit or opAssign is called, depend on left, not right side of assignment. Object 'a' didn't exists prior, so postblit is called, and copy ctor is called with respect of 'a' as 'this' argument.

What had confused me, was the point, that it doesn't matter if you return by value or by ref, you get the same output for this specific case.
That did not feel right.
But thanks to you.
May 23, 2013
On 05/23/13 13:57, Namespace wrote:
> I know that D has (sadly) no C++ references, but I still think that
> 
> A a = some_existing_A;
> 
> should call opAssign.

Not opAssign, but user-defined copy-constructor. But D does not have them either...

artur
May 23, 2013
On Thursday, 23 May 2013 at 12:29:04 UTC, Artur Skawina wrote:
> On 05/23/13 13:57, Namespace wrote:
>> I know that D has (sadly) no C++ references, but I still think that
>> 
>> A a = some_existing_A;
>> 
>> should call opAssign.
>
> Not opAssign, but user-defined copy-constructor. But D does not have
> them either...
>
> artur

That would be a solution.
May 23, 2013
On 05/23/13 14:30, Namespace wrote:
> On Thursday, 23 May 2013 at 12:29:04 UTC, Artur Skawina wrote:
>> On 05/23/13 13:57, Namespace wrote:
>>> I know that D has (sadly) no C++ references, but I still think that
>>>
>>> A a = some_existing_A;
>>>
>>> should call opAssign.
>>
>> Not opAssign, but user-defined copy-constructor. But D does not have them either...
> 
> That would be a solution.

They are required anyway, for several reasons.

Right now, you /can/ do:

   A a = A(some_existing_A);

but, because 'A a = some_existing_A' will bypass your cpctor and call the postblit, it's too dangerous. Unless you mark the latter as @disabled, which of course causes other problems.

artur
1 2
Next ›   Last »