pass-by-ref semantics for structs (was Deque impl.)

monarch_dodra monarchdodra at gmail.com
Thu Jan 31 04:31:32 PST 2013


On Thursday, 31 January 2013 at 12:28:00 UTC, d coder wrote:
> On Thu, Jan 31, 2013 at 5:30 PM, monarch_dodra 
> <monarchdodra at gmail.com> wrote:
>> The pull is kind of stuck in limbo, specifically because of 
>> the problems
>> associated with implementing reference semantics with structs 
>> :/
>
>
> Thanks for the enlightening email.
>
> I am of the considered view that reference semantics with 
> structs in D
> is tough (if not impossible) with default constructor and 
> postblit
> constructor (used when passing objects). This is because you 
> can not
> initialize any object (wrapped in the struct) in the default
> constructor and if you are passing the struct as a function 
> parameter,
> it is not possible to initialize these internal objects (before
> passing them) in the postblit constructor. I faced this in some 
> of my
> code. Do not know if you are facing the same scenario in the 
> DList
> implementation.
>
> Are there any possible solutions in the pipe?
>
> Regards
> - Puneet

This keeps coming up, so I'll wrap up how it goes:

Conclusions:
* The language will not change.
* Use "static S opCall()" to emulate no-arg constructor

The conversation:
- "But opCall is not good enough: It's not a constructor"
- "But it's all you'll get"

If you want some history, specifically, you need to look for 
"no-arg constructor".


More information about the Digitalmars-d mailing list