Copy Constructor DIP
Guillaume Piolat
first.last at gmail.com
Tue Jul 10 12:34:34 UTC 2018
On Tuesday, 10 July 2018 at 11:58:53 UTC, Jonathan M Davis wrote:
>>
>> Does it allow to remove the "T.init must always be valid for
>> structs" rule?
>
> Why would it? init is the state of the object before any
> constructor runs, and quite a few things rely on it. The fact
> that we've allowed default initialization to be disabled
> already causes plenty of problems as it is. It's occasionally
> useful, but it definitely complicates things. D was designed
> with the idea that every type has an init value.
>
> What problem are you trying to solve here?
>
> - Jonathan M Davis
None, I was just reacting to
https://medium.com/@feepingcreature/d-structs-dont-work-for-domain-data-c09332349f43
Proper D structs almost require having a T.init that is valid,
and in turn many public members may get to check for internal
validity before doing things. This is in stark contrast to C++
where "proper" constructor is guaranteed so you don't check such
validity.
What is a "correct" T.init for a mutex RAII struct? It is a null
handle value. It's obviously an invalid value for any purpose,
but the D wrapper has to be a valid struct.
More information about the Digitalmars-d
mailing list